2018-06-14 09:15:52 +00:00
|
|
|
const fs = require('fs');
|
2019-02-03 18:53:44 +00:00
|
|
|
const got = require('../../lib/util/got');
|
2018-07-09 09:14:06 +00:00
|
|
|
const datasource = require('../../lib/datasource');
|
2018-06-14 09:15:52 +00:00
|
|
|
|
2019-02-03 18:53:44 +00:00
|
|
|
jest.mock('../../lib/util/got');
|
2019-02-22 09:34:01 +00:00
|
|
|
jest.mock('../../lib/util/host-rules');
|
2018-06-14 09:15:52 +00:00
|
|
|
|
2019-03-11 15:50:10 +00:00
|
|
|
const pkgListV3 = fs.readFileSync(
|
|
|
|
'test/datasource/nuget/_fixtures/nunitV3.json',
|
|
|
|
'utf8'
|
|
|
|
);
|
2019-02-19 14:58:42 +00:00
|
|
|
const pkgListV3WithoutProkjectUrl = fs.readFileSync(
|
2019-03-11 15:50:10 +00:00
|
|
|
'test/datasource/nuget/_fixtures/nunitV3_withoutProjectUrl.json',
|
2019-02-19 14:58:42 +00:00
|
|
|
'utf8'
|
|
|
|
);
|
|
|
|
const pkgInfoV3FromNuget = fs.readFileSync(
|
2019-03-11 15:50:10 +00:00
|
|
|
'test/datasource/nuget/_fixtures/nunitv3_nuget-org.xml',
|
2019-02-19 14:58:42 +00:00
|
|
|
'utf8'
|
|
|
|
);
|
|
|
|
|
2019-03-11 15:50:10 +00:00
|
|
|
const pkgListV2 = fs.readFileSync(
|
|
|
|
'test/datasource/nuget/_fixtures/nunitV2.xml',
|
|
|
|
'utf8'
|
|
|
|
);
|
2019-02-22 09:34:01 +00:00
|
|
|
const pkgListV2WithoutProjectUrl = fs.readFileSync(
|
2019-03-11 15:50:10 +00:00
|
|
|
'test/datasource/nuget/_fixtures/nunitV2_withoutProjectUrl.xml',
|
2019-02-19 14:58:42 +00:00
|
|
|
'utf8'
|
|
|
|
);
|
|
|
|
|
|
|
|
const nugetIndexV3 = fs.readFileSync(
|
2019-03-11 15:50:10 +00:00
|
|
|
'test/datasource/nuget/_fixtures/indexV3.json',
|
2019-02-19 14:58:42 +00:00
|
|
|
'utf8'
|
|
|
|
);
|
|
|
|
|
2019-02-22 09:34:01 +00:00
|
|
|
const configNoRegistryUrls = {
|
|
|
|
datasource: 'nuget',
|
|
|
|
lookupName: 'nunit',
|
|
|
|
};
|
|
|
|
|
2019-02-19 14:58:42 +00:00
|
|
|
const configV3V2 = {
|
|
|
|
datasource: 'nuget',
|
|
|
|
lookupName: 'nunit',
|
|
|
|
registryUrls: [
|
|
|
|
'https://api.nuget.org/v3/index.json',
|
|
|
|
'https://www.nuget.org/api/v2/',
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
const configV2 = {
|
|
|
|
datasource: 'nuget',
|
|
|
|
lookupName: 'nunit',
|
|
|
|
registryUrls: ['https://www.nuget.org/api/v2/'],
|
|
|
|
};
|
|
|
|
|
|
|
|
const configV3 = {
|
|
|
|
datasource: 'nuget',
|
|
|
|
lookupName: 'nunit',
|
|
|
|
registryUrls: ['https://api.nuget.org/v3/index.json'],
|
|
|
|
};
|
|
|
|
|
|
|
|
const configV3NotNugetOrg = {
|
|
|
|
datasource: 'nuget',
|
|
|
|
lookupName: 'nunit',
|
|
|
|
registryUrls: ['https://myprivatefeed/index.json'],
|
|
|
|
};
|
2018-06-14 09:15:52 +00:00
|
|
|
|
2018-06-14 13:52:37 +00:00
|
|
|
describe('datasource/nuget', () => {
|
2019-04-22 15:12:16 +00:00
|
|
|
beforeEach(() => global.renovateCache.rmAll());
|
2018-07-29 14:04:00 +00:00
|
|
|
describe('getPkgReleases', () => {
|
2018-12-25 11:31:51 +00:00
|
|
|
beforeEach(() => {
|
2019-02-22 09:34:01 +00:00
|
|
|
jest.resetAllMocks();
|
2018-12-25 11:31:51 +00:00
|
|
|
global.repoCache = {};
|
|
|
|
});
|
2019-02-19 14:58:42 +00:00
|
|
|
|
|
|
|
it(`can't detect nuget feed version`, async () => {
|
|
|
|
const config = {
|
|
|
|
datasource: 'nuget',
|
|
|
|
lookupName: 'nunit',
|
|
|
|
registryUrls: ['#$#api.nuget.org/v3/index.xml'],
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(
|
|
|
|
await datasource.getPkgReleases({
|
|
|
|
...config,
|
|
|
|
})
|
|
|
|
).toBeNull();
|
|
|
|
});
|
|
|
|
|
2019-02-22 09:34:01 +00:00
|
|
|
it('queries the default nuget feed if no registries are supplied', async () => {
|
|
|
|
await datasource.getPkgReleases({
|
|
|
|
...configNoRegistryUrls,
|
|
|
|
});
|
|
|
|
expect(got.mock.calls[0][0]).toEqual(
|
|
|
|
'https://api.nuget.org/v3/index.json'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2019-02-19 14:58:42 +00:00
|
|
|
it(`can't get packages list (v3)`, async () => {
|
|
|
|
got.mockReturnValueOnce({
|
|
|
|
body: JSON.parse(nugetIndexV3),
|
|
|
|
statusCode: 200,
|
|
|
|
});
|
|
|
|
got.mockReturnValueOnce({
|
|
|
|
statusCode: 500,
|
|
|
|
});
|
|
|
|
const res = await datasource.getPkgReleases({
|
|
|
|
...configV3,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(res).toBeNull();
|
|
|
|
});
|
|
|
|
it(`empty packages list (v3)`, async () => {
|
|
|
|
got.mockReturnValueOnce({
|
|
|
|
body: JSON.parse(nugetIndexV3),
|
|
|
|
statusCode: 200,
|
|
|
|
});
|
|
|
|
got.mockReturnValueOnce({
|
|
|
|
body: JSON.parse('{"totalHits": 0}'),
|
|
|
|
statusCode: 200,
|
|
|
|
});
|
|
|
|
const res = await datasource.getPkgReleases({
|
|
|
|
...configV3,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(res).toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns null for empty result (v3v2)', async () => {
|
|
|
|
got.mockReturnValueOnce({});
|
|
|
|
expect(
|
|
|
|
await datasource.getPkgReleases({
|
|
|
|
...configV3V2,
|
|
|
|
})
|
|
|
|
).toBeNull();
|
|
|
|
});
|
|
|
|
it('returns null for empty result (v2)', async () => {
|
|
|
|
got.mockReturnValueOnce({});
|
|
|
|
expect(
|
|
|
|
await datasource.getPkgReleases({
|
|
|
|
...configV2,
|
|
|
|
})
|
|
|
|
).toBeNull();
|
|
|
|
});
|
|
|
|
it('returns null for empty result (v3)', async () => {
|
2018-06-14 09:15:52 +00:00
|
|
|
got.mockReturnValueOnce({});
|
2019-01-28 05:40:37 +00:00
|
|
|
expect(
|
2019-02-04 08:41:22 +00:00
|
|
|
await datasource.getPkgReleases({
|
2019-02-19 14:58:42 +00:00
|
|
|
...configV3,
|
|
|
|
})
|
|
|
|
).toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns null for non 200 (v3v2)', async () => {
|
|
|
|
got.mockImplementationOnce(() =>
|
|
|
|
Promise.reject({
|
|
|
|
statusCode: 500,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
await datasource.getPkgReleases({
|
|
|
|
...configV3V2,
|
|
|
|
})
|
|
|
|
).toBeNull();
|
|
|
|
});
|
|
|
|
it('returns null for non 200 (v3)', async () => {
|
|
|
|
got.mockImplementationOnce(() =>
|
|
|
|
Promise.reject({
|
|
|
|
statusCode: 500,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
await datasource.getPkgReleases({
|
|
|
|
...configV3,
|
2019-02-04 08:41:22 +00:00
|
|
|
})
|
2019-01-28 05:40:37 +00:00
|
|
|
).toBeNull();
|
2018-06-14 09:15:52 +00:00
|
|
|
});
|
2019-02-19 14:58:42 +00:00
|
|
|
it('returns null for non 200 (v3)', async () => {
|
2018-06-14 13:52:37 +00:00
|
|
|
got.mockImplementationOnce(() =>
|
|
|
|
Promise.reject({
|
2019-02-19 14:58:42 +00:00
|
|
|
statusCode: 500,
|
2018-06-14 13:52:37 +00:00
|
|
|
})
|
2018-06-14 09:15:52 +00:00
|
|
|
);
|
2019-01-28 05:40:37 +00:00
|
|
|
expect(
|
2019-02-04 08:41:22 +00:00
|
|
|
await datasource.getPkgReleases({
|
2019-02-19 14:58:42 +00:00
|
|
|
...configV2,
|
|
|
|
})
|
|
|
|
).toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns null for unknown error (v3v2)', async () => {
|
|
|
|
got.mockImplementationOnce(() => {
|
|
|
|
throw new Error();
|
|
|
|
});
|
|
|
|
expect(
|
|
|
|
await datasource.getPkgReleases({
|
|
|
|
...configV3V2,
|
|
|
|
})
|
|
|
|
).toBeNull();
|
|
|
|
});
|
|
|
|
it('returns null for unknown error in getPkgReleasesFromV3Feed (v3)', async () => {
|
|
|
|
got.mockImplementationOnce(() => {
|
|
|
|
throw new Error();
|
|
|
|
});
|
|
|
|
expect(
|
|
|
|
await datasource.getPkgReleases({
|
|
|
|
...configV3,
|
|
|
|
})
|
|
|
|
).toBeNull();
|
|
|
|
});
|
|
|
|
it('returns null for unknown error in getQueryUrlForV3Feed (v3)', async () => {
|
|
|
|
got.mockReturnValueOnce({
|
|
|
|
body: JSON.parse(nugetIndexV3),
|
|
|
|
statusCode: 200,
|
|
|
|
});
|
|
|
|
got.mockImplementationOnce(() => {
|
|
|
|
throw new Error();
|
|
|
|
});
|
|
|
|
expect(
|
|
|
|
await datasource.getPkgReleases({
|
|
|
|
...configV3,
|
2019-02-04 08:41:22 +00:00
|
|
|
})
|
2019-01-28 05:40:37 +00:00
|
|
|
).toBeNull();
|
2018-06-14 13:52:37 +00:00
|
|
|
});
|
2019-02-19 14:58:42 +00:00
|
|
|
it('returns null for unknown error (v2)', async () => {
|
2018-06-14 13:52:37 +00:00
|
|
|
got.mockImplementationOnce(() => {
|
|
|
|
throw new Error();
|
|
|
|
});
|
2019-01-28 05:40:37 +00:00
|
|
|
expect(
|
2019-02-04 08:41:22 +00:00
|
|
|
await datasource.getPkgReleases({
|
2019-02-19 14:58:42 +00:00
|
|
|
...configV2,
|
2019-02-04 08:41:22 +00:00
|
|
|
})
|
2019-01-28 05:40:37 +00:00
|
|
|
).toBeNull();
|
2018-06-14 13:52:37 +00:00
|
|
|
});
|
2019-02-19 14:58:42 +00:00
|
|
|
|
|
|
|
it('processes real data (v3) feed is a nuget.org', async () => {
|
|
|
|
got.mockReturnValueOnce({
|
|
|
|
body: JSON.parse(nugetIndexV3),
|
|
|
|
statusCode: 200,
|
|
|
|
});
|
2018-06-14 13:52:37 +00:00
|
|
|
got.mockReturnValueOnce({
|
2019-02-19 14:58:42 +00:00
|
|
|
body: JSON.parse(pkgListV3),
|
|
|
|
statusCode: 200,
|
2018-06-14 13:52:37 +00:00
|
|
|
});
|
|
|
|
got.mockReturnValueOnce({
|
2019-02-19 14:58:42 +00:00
|
|
|
body: pkgInfoV3FromNuget,
|
|
|
|
statusCode: 200,
|
2018-06-14 13:52:37 +00:00
|
|
|
});
|
2019-02-04 08:41:22 +00:00
|
|
|
const res = await datasource.getPkgReleases({
|
2019-02-19 14:58:42 +00:00
|
|
|
...configV3,
|
|
|
|
});
|
|
|
|
expect(res).not.toBeNull();
|
|
|
|
expect(res).toMatchSnapshot();
|
|
|
|
expect(res.sourceUrl).toBeDefined();
|
|
|
|
});
|
|
|
|
it('processes real data (v3) feed is not a nuget.org', async () => {
|
|
|
|
got.mockReturnValueOnce({
|
|
|
|
body: JSON.parse(nugetIndexV3),
|
|
|
|
statusCode: 200,
|
|
|
|
});
|
|
|
|
got.mockReturnValueOnce({
|
|
|
|
body: JSON.parse(pkgListV3),
|
|
|
|
statusCode: 200,
|
|
|
|
});
|
|
|
|
const res = await datasource.getPkgReleases({
|
|
|
|
...configV3NotNugetOrg,
|
|
|
|
});
|
|
|
|
expect(res).not.toBeNull();
|
|
|
|
expect(res).toMatchSnapshot();
|
|
|
|
expect(res.sourceUrl).toBeDefined();
|
|
|
|
});
|
|
|
|
it('processes real data without project url (v3)', async () => {
|
|
|
|
got.mockReturnValueOnce({
|
|
|
|
body: JSON.parse(nugetIndexV3),
|
|
|
|
statusCode: 200,
|
|
|
|
});
|
|
|
|
got.mockReturnValueOnce({
|
|
|
|
body: JSON.parse(pkgListV3WithoutProkjectUrl),
|
|
|
|
statusCode: 200,
|
|
|
|
});
|
|
|
|
const res = await datasource.getPkgReleases({
|
|
|
|
...configV3NotNugetOrg,
|
|
|
|
});
|
|
|
|
expect(res).not.toBeNull();
|
|
|
|
expect(res).toMatchSnapshot();
|
|
|
|
expect(res.sourceUrl).not.toBeDefined();
|
|
|
|
});
|
|
|
|
it('processes real data (v2)', async () => {
|
|
|
|
got.mockReturnValueOnce({
|
|
|
|
body: pkgListV2,
|
|
|
|
statusCode: 200,
|
|
|
|
});
|
|
|
|
const res = await datasource.getPkgReleases({
|
|
|
|
...configV2,
|
2019-02-04 08:41:22 +00:00
|
|
|
});
|
2018-06-14 13:52:37 +00:00
|
|
|
expect(res).not.toBeNull();
|
|
|
|
expect(res).toMatchSnapshot();
|
2018-12-10 04:59:28 +00:00
|
|
|
expect(res.sourceUrl).toBeDefined();
|
2018-06-14 09:15:52 +00:00
|
|
|
});
|
2019-02-19 14:58:42 +00:00
|
|
|
it('processes real data without project url (v2)', async () => {
|
|
|
|
got.mockReturnValueOnce({
|
2019-02-22 09:34:01 +00:00
|
|
|
body: pkgListV2WithoutProjectUrl,
|
2019-02-19 14:58:42 +00:00
|
|
|
statusCode: 200,
|
|
|
|
});
|
|
|
|
const res = await datasource.getPkgReleases({
|
|
|
|
...configV2,
|
|
|
|
});
|
|
|
|
expect(res).not.toBeNull();
|
|
|
|
expect(res).toMatchSnapshot();
|
|
|
|
expect(res.sourceUrl).not.toBeDefined();
|
|
|
|
});
|
2018-06-14 09:15:52 +00:00
|
|
|
});
|
|
|
|
});
|