dockerhub: getRepositoryTags

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2023-02-14 04:30:26 +01:00
parent 01219141e4
commit c2dfc9dae8
5 changed files with 8313 additions and 2 deletions

View File

@@ -19,13 +19,15 @@ import * as fs from 'fs';
import * as path from 'path';
import {DockerHub} from '../src/dockerhub';
import {RepositoryResponse} from '../src/types/dockerhub';
import {RepositoryResponse, RepositoryTagsResponse} from '../src/types/dockerhub';
beforeEach(() => {
jest.clearAllMocks();
});
import repoInfoFixture from './fixtures/dockerhub-repoinfo.json';
import repoTagsFixture from './fixtures/dockerhub-repotags.json';
import repoAllTagsFixture from './fixtures/dockerhub-repoalltags.json';
describe('getRepository', () => {
it('returns repo info', async () => {
@@ -50,6 +52,54 @@ describe('getRepository', () => {
});
});
describe('getRepositoryTags', () => {
it('return repo tags', async () => {
jest.spyOn(DockerHub.prototype, 'getRepositoryTags').mockImplementation((): Promise<RepositoryTagsResponse> => {
return <Promise<RepositoryTagsResponse>>(repoTagsFixture as unknown);
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any
jest.spyOn(DockerHub as any, 'login').mockReturnValue('jwt_token');
const dockerhub = await DockerHub.build({
credentials: {
username: 'foo',
password: '0123456-7890-0000-1111-222222222'
}
});
const resp = await dockerhub.getRepositoryTags({
namespace: 'crazymax',
name: 'diun'
});
expect(resp.count).toBeGreaterThan(0);
expect(resp.next).not.toBeNull();
expect(resp.results.length).toBeGreaterThan(0);
expect(resp.results[0].last_updater_username).toEqual('crazymax');
});
});
describe('getRepositoryAllTags', () => {
it('return repo all tags', async () => {
jest.spyOn(DockerHub.prototype, 'getRepositoryAllTags').mockImplementation((): Promise<RepositoryTagsResponse> => {
return <Promise<RepositoryTagsResponse>>(repoAllTagsFixture as unknown);
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any
jest.spyOn(DockerHub as any, 'login').mockReturnValue('jwt_token');
const dockerhub = await DockerHub.build({
credentials: {
username: 'foo',
password: '0123456-7890-0000-1111-222222222'
}
});
const resp = await dockerhub.getRepositoryAllTags({
namespace: 'crazymax',
name: 'diun'
});
expect(resp.count).toBeGreaterThan(0);
expect(resp.next).toBeNull();
expect(resp.results.length).toBeGreaterThan(0);
expect(resp.results[0].last_updater_username).toEqual('crazymax');
});
});
describe('updateRepoDescription', () => {
it.skip('set repo description', async () => {
const dockerhub = await DockerHub.build({

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff