Skip to content

Commit

Permalink
refactor: Import index for datasource tests (part 2) (#6546)
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov committed Jun 18, 2020
1 parent ed7483a commit bd98334
Show file tree
Hide file tree
Showing 26 changed files with 982 additions and 927 deletions.
5 changes: 3 additions & 2 deletions lib/datasource/docker/index.spec.ts
Expand Up @@ -496,8 +496,9 @@ describe('api/docker', () => {
.reply(200, null)
.get('/my/node/tags/list?n=10000')
.replyWithError('error');
const res = await docker.getReleases({
lookupName: 'my/node',
const res = await getPkgReleases({
datasource: docker.id,
depName: 'my/node',
});
expect(res).toBeNull();
expect(httpMock.getTrace()).toMatchSnapshot();
Expand Down
20 changes: 14 additions & 6 deletions lib/datasource/git-refs/index.spec.ts
@@ -1,11 +1,12 @@
import fs from 'fs-extra';
import _simpleGit from 'simple-git/promise';
import { getDigest, getReleases } from '.';
import { getPkgReleases } from '..';
import { id as datasource, getDigest } from '.';

jest.mock('simple-git/promise');
const simpleGit: any = _simpleGit;

const lookupName = 'https://github.com/example/example.git';
const depName = 'https://github.com/example/example.git';

const lsRemote1 = fs.readFileSync(
'lib/datasource/git-refs/__fixtures__/ls-remote-1.txt',
Expand All @@ -20,7 +21,10 @@ describe('datasource/git-refs', () => {
return Promise.resolve(null);
},
});
const versions = await getReleases({ lookupName });
const versions = await getPkgReleases({
datasource,
depName,
});
expect(versions).toBeNull();
});
it('returns nil if remote call throws exception', async () => {
Expand All @@ -29,7 +33,10 @@ describe('datasource/git-refs', () => {
throw new Error();
},
});
const versions = await getReleases({ lookupName });
const versions = await getPkgReleases({
datasource,
depName,
});
expect(versions).toBeNull();
});
it('returns versions filtered from tags', async () => {
Expand All @@ -39,8 +46,9 @@ describe('datasource/git-refs', () => {
},
});

const versions = await getReleases({
lookupName,
const versions = await getPkgReleases({
datasource,
depName,
});
expect(versions).toMatchSnapshot();
const result = versions.releases.map((x) => x.version).sort();
Expand Down
28 changes: 21 additions & 7 deletions lib/datasource/git-submodules/index.spec.ts
@@ -1,11 +1,13 @@
import _simpleGit from 'simple-git/promise';
import { getDigest, getReleases } from '.';
import { getPkgReleases } from '..';
import { id as versioning } from '../../versioning/git';
import { id as datasource, getDigest } from '.';

jest.mock('simple-git/promise');
const simpleGit: any = _simpleGit;

const lookupName = 'https://github.com/example/example.git';
const registryUrls = [lookupName, 'master'];
const depName = 'https://github.com/example/example.git';
const registryUrls = [depName, 'master'];

describe('datasource/git-submoduless', () => {
describe('getReleases', () => {
Expand All @@ -15,7 +17,12 @@ describe('datasource/git-submoduless', () => {
return Promise.resolve(null);
},
});
const versions = await getReleases({ lookupName, registryUrls });
const versions = await getPkgReleases({
datasource,
versioning,
depName,
registryUrls,
});
expect(versions).toBeNull();
});
it('returns null if remote call throws exception', async () => {
Expand All @@ -24,7 +31,12 @@ describe('datasource/git-submoduless', () => {
throw new Error();
},
});
const versions = await getReleases({ lookupName, registryUrls });
const versions = await getPkgReleases({
datasource,
versioning,
depName,
registryUrls,
});
expect(versions).toBeNull();
});
it('returns versions filtered from tags', async () => {
Expand All @@ -34,8 +46,10 @@ describe('datasource/git-submoduless', () => {
},
});

const versions = await getReleases({
lookupName,
const versions = await getPkgReleases({
datasource,
versioning,
depName,
registryUrls,
});
const result = versions.releases.map((x) => x.version).sort();
Expand Down
20 changes: 11 additions & 9 deletions lib/datasource/git-tags/index.spec.ts
@@ -1,11 +1,12 @@
import fs from 'fs-extra';
import _simpleGit from 'simple-git/promise';
import { getDigest, getReleases } from '.';
import { getPkgReleases } from '..';
import { id as datasource, getDigest } from '.';

jest.mock('simple-git/promise');
const simpleGit: any = _simpleGit;

const lookupName = 'https://github.com/example/example.git';
const depName = 'https://github.com/example/example.git';

const lsRemote1 = fs.readFileSync(
'lib/datasource/git-refs/__fixtures__/ls-remote-1.txt',
Expand All @@ -20,7 +21,7 @@ describe('datasource/git-tags', () => {
return Promise.resolve(null);
},
});
const versions = await getReleases({ lookupName });
const versions = await getPkgReleases({ datasource, depName });
expect(versions).toBeNull();
});
it('returns nil if remote call throws exception', async () => {
Expand All @@ -29,7 +30,7 @@ describe('datasource/git-tags', () => {
throw new Error();
},
});
const versions = await getReleases({ lookupName });
const versions = await getPkgReleases({ datasource, depName });
expect(versions).toBeNull();
});
it('returns versions filtered from tags', async () => {
Expand All @@ -39,8 +40,9 @@ describe('datasource/git-tags', () => {
},
});

const versions = await getReleases({
lookupName,
const versions = await getPkgReleases({
datasource,
depName,
});
expect(versions).toMatchSnapshot();
});
Expand All @@ -53,7 +55,7 @@ describe('datasource/git-tags', () => {
},
});
const digest = await getDigest(
{ lookupName: 'a tag to look up' },
{ datasource, depName: 'a tag to look up' },
'notfound'
);
expect(digest).toBeNull();
Expand All @@ -65,7 +67,7 @@ describe('datasource/git-tags', () => {
},
});
const digest = await getDigest(
{ lookupName: 'a tag to look up' },
{ datasource, depName: 'a tag to look up' },
'v1.0.2'
);
expect(digest).toMatchSnapshot();
Expand All @@ -77,7 +79,7 @@ describe('datasource/git-tags', () => {
},
});
const digest = await getDigest(
{ lookupName: 'another tag to look up' },
{ datasource, depName: 'another tag to look up' },
undefined
);
expect(digest).toMatchSnapshot();
Expand Down
10 changes: 0 additions & 10 deletions lib/datasource/github-releases/__snapshots__/index.spec.ts.snap
Expand Up @@ -3,16 +3,6 @@
exports[`datasource/github-releases getReleases returns releases 1`] = `
Object {
"releases": Array [
Object {
"gitRef": "a",
"releaseTimestamp": "2020-03-09T13:00:00Z",
"version": "a",
},
Object {
"gitRef": "v",
"releaseTimestamp": "2020-03-09T12:00:00Z",
"version": "v",
},
Object {
"gitRef": "1.0.0",
"releaseTimestamp": "2020-03-09T11:00:00Z",
Expand Down
10 changes: 6 additions & 4 deletions lib/datasource/github-releases/index.spec.ts
@@ -1,6 +1,7 @@
import { getPkgReleases } from '..';
import * as httpMock from '../../../test/httpMock';
import * as _hostRules from '../../util/host-rules';
import * as github from '.';
import { id as datasource } from '.';

jest.mock('../../util/host-rules');
const hostRules: any = _hostRules;
Expand Down Expand Up @@ -32,11 +33,12 @@ describe('datasource/github-releases', () => {
{ tag_name: 'v1.1.0', published_at: '2020-03-09T10:00:00Z' },
]);

const res = await github.getReleases({
lookupName: 'some/dep',
const res = await getPkgReleases({
datasource,
depName: 'some/dep',
});
expect(res).toMatchSnapshot();
expect(res.releases).toHaveLength(4);
expect(res.releases).toHaveLength(2);
expect(
res.releases.find((release) => release.version === 'v1.1.0')
).toBeDefined();
Expand Down
7 changes: 4 additions & 3 deletions lib/datasource/github-tags/index.spec.ts
@@ -1,3 +1,4 @@
import { getPkgReleases } from '..';
import * as httpMock from '../../../test/httpMock';
import * as _hostRules from '../../util/host-rules';
import * as github from '.';
Expand Down Expand Up @@ -88,15 +89,15 @@ describe('datasource/github-tags', () => {
});
});
describe('getReleases', () => {
const lookupName = 'some/dep2';
const depName = 'some/dep2';

it('returns tags', async () => {
const body = [{ name: 'v1.0.0' }, { name: 'v1.1.0' }];
httpMock
.scope(githubApiHost)
.get(`/repos/${lookupName}/tags?per_page=100`)
.get(`/repos/${depName}/tags?per_page=100`)
.reply(200, body);
const res = await github.getReleases({ lookupName });
const res = await getPkgReleases({ datasource: github.id, depName });
expect(res).toMatchSnapshot();
expect(res.releases).toHaveLength(2);
expect(httpMock.getTrace()).toMatchSnapshot();
Expand Down
4 changes: 0 additions & 4 deletions lib/datasource/gitlab-tags/__snapshots__/index.spec.ts.snap
Expand Up @@ -10,12 +10,10 @@ Object {
},
Object {
"gitRef": "v1.1.0",
"releaseTimestamp": undefined,
"version": "v1.1.0",
},
Object {
"gitRef": "v1.1.1",
"releaseTimestamp": undefined,
"version": "v1.1.1",
},
],
Expand Down Expand Up @@ -43,12 +41,10 @@ Object {
"releases": Array [
Object {
"gitRef": "v1.0.0",
"releaseTimestamp": undefined,
"version": "v1.0.0",
},
Object {
"gitRef": "v1.1.0",
"releaseTimestamp": undefined,
"version": "v1.1.0",
},
],
Expand Down
13 changes: 8 additions & 5 deletions lib/datasource/gitlab-tags/index.spec.ts
@@ -1,5 +1,6 @@
import { getPkgReleases } from '..';
import * as httpMock from '../../../test/httpMock';
import * as gitlab from '.';
import { id as datasource } from '.';

describe('datasource/gitlab-tags', () => {
beforeEach(() => {
Expand Down Expand Up @@ -27,9 +28,10 @@ describe('datasource/gitlab-tags', () => {
.scope('https://gitlab.company.com')
.get('/api/v4/api/v4/projects/some%2Fdep2/repository/tags?per_page=100')
.reply(200, body);
const res = await gitlab.getReleases({
const res = await getPkgReleases({
datasource,
registryUrls: ['https://gitlab.company.com/api/v4/'],
lookupName: 'some/dep2',
depName: 'some/dep2',
});
expect(res).toMatchSnapshot();
expect(res.releases).toHaveLength(3);
Expand All @@ -42,8 +44,9 @@ describe('datasource/gitlab-tags', () => {
.scope('https://gitlab.com')
.get('/api/v4/projects/some%2Fdep2/repository/tags?per_page=100')
.reply(200, body);
const res = await gitlab.getReleases({
lookupName: 'some/dep2',
const res = await getPkgReleases({
datasource,
depName: 'some/dep2',
});
expect(res).toMatchSnapshot();
expect(res.releases).toHaveLength(2);
Expand Down

0 comments on commit bd98334

Please sign in to comment.