1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
import MockAdapter from 'axios-mock-adapter';
import * as harborRegistryApi from '~/api/harbor_registry';
import axios from '~/lib/utils/axios_utils';
import httpStatus from '~/lib/utils/http_status';
describe('~/api/harbor_registry', () => {
let mock;
beforeEach(() => {
mock = new MockAdapter(axios);
jest.spyOn(axios, 'get');
});
afterEach(() => {
mock.restore();
});
describe('getHarborRepositoriesList', () => {
it('fetches the harbor repositories of the configured harbor project', () => {
const requestPath = '/flightjs/Flight/-/harbor/repositories';
const expectedUrl = `${requestPath}.json`;
const expectedParams = {
limit: 10,
page: 1,
sort: 'update_time desc',
requestPath,
};
const expectResponse = [
{
harbor_id: 1,
name: 'test-project/image-1',
artifact_count: 1,
creation_time: '2022-07-16T08:20:34.851Z',
update_time: '2022-07-16T08:20:34.851Z',
harbor_project_id: 2,
pull_count: 0,
location: 'http://demo.harbor.com/harbor/projects/2/repositories/image-1',
},
];
mock.onGet(expectedUrl).reply(httpStatus.OK, expectResponse);
return harborRegistryApi.getHarborRepositoriesList(expectedParams).then(({ data }) => {
expect(data).toEqual(expectResponse);
});
});
});
describe('getHarborArtifacts', () => {
it('fetches the artifacts of a particular harbor repository', () => {
const requestPath = '/flightjs/Flight/-/harbor/repositories';
const repoName = 'image-1';
const expectedUrl = `${requestPath}/${repoName}/artifacts.json`;
const expectedParams = {
limit: 10,
page: 1,
sort: 'name asc',
repoName,
requestPath,
};
const expectResponse = [
{
harbor_id: 1,
digest: 'sha256:dcdf379c574e1773d703f0c0d56d67594e7a91d6b84d11ff46799f60fb081c52',
size: 775241,
push_time: '2022-07-16T08:20:34.867Z',
tags: ['v2', 'v1', 'latest'],
},
];
mock.onGet(expectedUrl).reply(httpStatus.OK, expectResponse);
return harborRegistryApi.getHarborArtifacts(expectedParams).then(({ data }) => {
expect(data).toEqual(expectResponse);
});
});
});
describe('getHarborTags', () => {
it('fetches the tags of a particular artifact', () => {
const requestPath = '/flightjs/Flight/-/harbor/repositories';
const repoName = 'image-1';
const digest = 'sha256:5d98daa36cdc8d6c7ed6579ce17230f0f9fd893a9012fc069cb7d714c0e3df35';
const expectedUrl = `${requestPath}/${repoName}/artifacts/${digest}/tags.json`;
const expectedParams = {
requestPath,
digest,
repoName,
};
const expectResponse = [
{
repositoryId: 4,
artifactId: 5,
id: 4,
name: 'latest',
pullTime: '0001-01-01T00:00:00.000Z',
pushTime: '2022-05-27T18:21:27.903Z',
signed: false,
immutable: false,
},
];
mock.onGet(expectedUrl).reply(httpStatus.OK, expectResponse);
return harborRegistryApi.getHarborTags(expectedParams).then(({ data }) => {
expect(data).toEqual(expectResponse);
});
});
});
});
|