diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-19 23:18:09 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-19 23:18:09 +0000 |
commit | 6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde (patch) | |
tree | dc4d20fe6064752c0bd323187252c77e0a89144b /spec/frontend/api | |
parent | 9868dae7fc0655bd7ce4a6887d4e6d487690eeed (diff) | |
download | gitlab-ce-6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde.tar.gz |
Add latest changes from gitlab-org/gitlab@15-4-stable-eev15.4.0-rc42
Diffstat (limited to 'spec/frontend/api')
-rw-r--r-- | spec/frontend/api/harbor_registry_spec.js | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/spec/frontend/api/harbor_registry_spec.js b/spec/frontend/api/harbor_registry_spec.js new file mode 100644 index 00000000000..8a4c377ebd1 --- /dev/null +++ b/spec/frontend/api/harbor_registry_spec.js @@ -0,0 +1,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); + }); + }); + }); +}); |