Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(datasource/docker): Convert to class #14194

Merged
merged 6 commits into from
Feb 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/datasource/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ClojureDatasource } from './clojure';
import { ConanDatasource } from './conan';
import { CrateDatasource } from './crate';
import { DartDatasource } from './dart';
import * as docker from './docker';
import { DockerDatasource } from './docker';
import { GalaxyDatasource } from './galaxy';
import { GalaxyCollectionDatasource } from './galaxy-collection';
import { GitRefsDatasource } from './git-refs';
Expand Down Expand Up @@ -52,7 +52,7 @@ api.set(ClojureDatasource.id, new ClojureDatasource());
api.set(ConanDatasource.id, new ConanDatasource());
api.set(CrateDatasource.id, new CrateDatasource());
api.set(DartDatasource.id, new DartDatasource());
api.set('docker', docker);
api.set(DockerDatasource.id, new DockerDatasource());
api.set(GalaxyDatasource.id, new GalaxyDatasource());
api.set(GalaxyCollectionDatasource.id, new GalaxyCollectionDatasource());
api.set(GitRefsDatasource.id, new GitRefsDatasource());
Expand Down
60 changes: 33 additions & 27 deletions lib/datasource/docker/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import * as httpMock from '../../../test/http-mock';
import { mocked, partial } from '../../../test/util';
import { EXTERNAL_HOST_ERROR } from '../../constants/error-messages';
import * as _hostRules from '../../util/host-rules';
import { Http } from '../../util/http';
import { MediaType } from './types';
import { getAuthHeaders, getRegistryRepository, id } from '.';
import { DockerDatasource, getAuthHeaders, getRegistryRepository } from '.';

const hostRules = mocked(_hostRules);

const http = new Http(DockerDatasource.id);

jest.mock('@aws-sdk/client-ecr');
jest.mock('../../util/host-rules');

Expand Down Expand Up @@ -121,6 +124,7 @@ describe('datasource/docker/index', () => {
});

const headers = await getAuthHeaders(
http,
'https://my.local.registry',
'https://my.local.registry/prefix'
);
Expand All @@ -138,6 +142,7 @@ Object {
});

const headers = await getAuthHeaders(
http,
'https://my.local.registry',
'https://my.local.registry/prefix'
);
Expand All @@ -158,6 +163,7 @@ Object {
.reply(401, '', {});

const headers = await getAuthHeaders(
http,
'https://my.local.registry',
'https://my.local.registry/prefix'
);
Expand Down Expand Up @@ -534,7 +540,7 @@ Object {
.get('/library/node/tags/list?n=10000')
.reply(403);
const res = await getPkgReleases({
datasource: id,
datasource: DockerDatasource.id,
depName: 'node',
registryUrls: ['https://docker.io'],
});
Expand Down Expand Up @@ -564,7 +570,7 @@ Object {
.get('/user/9287/repos?page=3&per_page=100')
.reply(200, { tags: ['latest'] }, {});
const config = {
datasource: id,
datasource: DockerDatasource.id,
depName: 'node',
registryUrls: ['https://registry.company.com'],
};
Expand All @@ -585,7 +591,7 @@ Object {
.get('/node/manifests/1.0.0')
.reply(200, '', {});
const res = await getPkgReleases({
datasource: id,
datasource: DockerDatasource.id,
depName: 'registry.company.com/node',
});
expect(res.releases).toHaveLength(1);
Expand All @@ -608,7 +614,7 @@ Object {
.get('/v2/bitnami/redis/manifests/5.0.12')
.reply(200, '', {});
const config = {
datasource: id,
datasource: DockerDatasource.id,
depName: 'bitnami/redis',
registryUrls: ['https://quay.io'],
};
Expand All @@ -624,7 +630,7 @@ Object {
)
.reply(500);
const config = {
datasource: id,
datasource: DockerDatasource.id,
depName: 'bitnami/redis',
registryUrls: ['https://quay.io'],
};
Expand All @@ -646,7 +652,7 @@ Object {
.reply(200);
expect(
await getPkgReleases({
datasource: id,
datasource: DockerDatasource.id,
depName: '123456789.dkr.ecr.us-east-1.amazonaws.com/node',
})
).toEqual({
Expand Down Expand Up @@ -700,7 +706,7 @@ Object {
});
expect(
await getPkgReleases({
datasource: id,
datasource: DockerDatasource.id,
depName: 'ecr-proxy.company.com/node',
})
).toEqual({
Expand Down Expand Up @@ -735,7 +741,7 @@ Object {
});
expect(
await getPkgReleases({
datasource: id,
datasource: DockerDatasource.id,
depName: 'ecr-proxy.company.com/node',
})
).toBeNull();
Expand Down Expand Up @@ -766,7 +772,7 @@ Object {
);
expect(
await getPkgReleases({
datasource: id,
datasource: DockerDatasource.id,
depName: 'ecr-proxy.company.com/node',
})
).toBeNull();
Expand All @@ -789,7 +795,7 @@ Object {
});
expect(
await getPkgReleases({
datasource: id,
datasource: DockerDatasource.id,
depName: 'ecr-proxy.company.com/node',
})
).toBeNull();
Expand Down Expand Up @@ -818,7 +824,7 @@ Object {
);
expect(
await getPkgReleases({
datasource: id,
datasource: DockerDatasource.id,
depName: 'ecr-proxy.company.com/node',
})
).toBeNull();
Expand All @@ -839,7 +845,7 @@ Object {
);
expect(
await getPkgReleases({
datasource: id,
datasource: DockerDatasource.id,
depName: 'ecr-proxy.company.com/node',
})
).toBeNull();
Expand All @@ -862,7 +868,7 @@ Object {
);
expect(
await getPkgReleases({
datasource: id,
datasource: DockerDatasource.id,
depName: 'ecr-proxy.company.com/node',
})
).toBeNull();
Expand All @@ -889,7 +895,7 @@ Object {
);
expect(
await getPkgReleases({
datasource: id,
datasource: DockerDatasource.id,
depName: 'ecr-proxy.company.com/node',
})
).toBeNull();
Expand Down Expand Up @@ -917,7 +923,7 @@ Object {
);
expect(
await getPkgReleases({
datasource: id,
datasource: DockerDatasource.id,
depName: 'ecr-proxy.company.com/node',
})
).toBeNull();
Expand Down Expand Up @@ -946,7 +952,7 @@ Object {
)
.reply(200, { token: 'test' });
const res = await getPkgReleases({
datasource: id,
datasource: DockerDatasource.id,
depName: 'node',
});
expect(res.releases).toHaveLength(1);
Expand Down Expand Up @@ -974,7 +980,7 @@ Object {
)
.reply(200, { token: 'test' });
const res = await getPkgReleases({
datasource: id,
datasource: DockerDatasource.id,
depName: 'docker.io/node',
});
expect(res.releases).toHaveLength(1);
Expand All @@ -1000,7 +1006,7 @@ Object {
.get('/kubernetes-dashboard-amd64/manifests/1.0.0')
.reply(200);
const res = await getPkgReleases({
datasource: id,
datasource: DockerDatasource.id,
depName: 'k8s.gcr.io/kubernetes-dashboard-amd64',
});
expect(res.releases).toHaveLength(1);
Expand All @@ -1014,7 +1020,7 @@ Object {
.get('/my/node/tags/list?n=10000')
.replyWithError('error');
const res = await getPkgReleases({
datasource: id,
datasource: DockerDatasource.id,
depName: 'my/node',
});
expect(res).toBeNull();
Expand All @@ -1039,7 +1045,7 @@ Object {
.get('/token?service=registry.docker.io&scope=repository:my/node:pull')
.reply(200, { token: 'some-token ' });
const res = await getPkgReleases({
datasource: id,
datasource: DockerDatasource.id,
depName: 'my/node',
registryUrls: ['https://index.docker.io/'],
});
Expand All @@ -1052,7 +1058,7 @@ Object {
'www-authenticate': 'Basic realm="My Private Docker Registry Server"',
});
const res = await getPkgReleases({
datasource: id,
datasource: DockerDatasource.id,
depName: 'node',
});
expect(res).toBeNull();
Expand Down Expand Up @@ -1092,7 +1098,7 @@ Object {
},
});
const res = await getPkgReleases({
datasource: id,
datasource: DockerDatasource.id,
depName: 'registry.company.com/node',
});
expect(res).toMatchSnapshot();
Expand Down Expand Up @@ -1128,7 +1134,7 @@ Object {
},
});
const res = await getPkgReleases({
datasource: id,
datasource: DockerDatasource.id,
depName: 'registry.company.com/node',
});
expect(res).toMatchSnapshot();
Expand All @@ -1148,7 +1154,7 @@ Object {
mediaType: MediaType.manifestV1,
});
const res = await getPkgReleases({
datasource: id,
datasource: DockerDatasource.id,
depName: 'registry.company.com/node',
});
expect(res).toMatchSnapshot();
Expand All @@ -1165,7 +1171,7 @@ Object {
.get('/node/manifests/latest')
.reply(200, {});
const res = await getPkgReleases({
datasource: id,
datasource: DockerDatasource.id,
depName: 'registry.company.com/node',
});
expect(res).toMatchSnapshot();
Expand Down Expand Up @@ -1208,7 +1214,7 @@ Object {
config: {},
});
const res = await getPkgReleases({
datasource: id,
datasource: DockerDatasource.id,
depName: 'registry.company.com/node',
});
expect(res).toMatchSnapshot();
Expand Down
Loading