From f6c5a6bad53069bf94bdd685682005cbb15f593c Mon Sep 17 00:00:00 2001 From: Sergei Zharinov <zharinov@users.noreply.github.com> Date: Tue, 11 May 2021 15:18:51 +0400 Subject: [PATCH] refactor(nuget): Extend test coverage (#9953) --- .../nuget/__snapshots__/index.spec.ts.snap | 466 ++++++++++++++++++ lib/datasource/nuget/index.spec.ts | 36 ++ lib/datasource/nuget/v3.ts | 2 +- 3 files changed, 503 insertions(+), 1 deletion(-) diff --git a/lib/datasource/nuget/__snapshots__/index.spec.ts.snap b/lib/datasource/nuget/__snapshots__/index.spec.ts.snap index 56acf1c134..3c30de410a 100644 --- a/lib/datasource/nuget/__snapshots__/index.spec.ts.snap +++ b/lib/datasource/nuget/__snapshots__/index.spec.ts.snap @@ -1570,6 +1570,472 @@ Array [ ] `; +exports[`datasource/nuget/index getReleases processes real data (v3) nuspec fetch 404 error 1`] = ` +Object { + "registryUrl": "https://api.nuget.org/v3/index.json", + "releases": Array [ + Object { + "releaseTimestamp": "2011-01-07T07:57:55.387Z", + "version": "2.5.7.10213", + }, + Object { + "releaseTimestamp": "2011-02-09T07:26:34.347Z", + "version": "2.5.9.10348", + }, + Object { + "releaseTimestamp": "2011-04-25T20:20:34.397Z", + "version": "2.5.10.11092", + }, + Object { + "isDeprecated": true, + "releaseTimestamp": "1900-01-01T00:00:00.000Z", + "version": "2.6.0.12051", + }, + Object { + "releaseTimestamp": "2012-02-24T04:03:05.290Z", + "version": "2.6.0.12054", + }, + Object { + "releaseTimestamp": "2012-08-05T03:08:28.403Z", + "version": "2.6.1", + }, + Object { + "releaseTimestamp": "2012-10-23T15:37:48.000Z", + "version": "2.6.2", + }, + Object { + "releaseTimestamp": "2013-10-11T01:52:53.417Z", + "version": "2.6.3", + }, + Object { + "releaseTimestamp": "2014-12-17T17:30:47.607Z", + "version": "2.6.4", + }, + Object { + "releaseTimestamp": "2018-04-20T04:23:59.217Z", + "version": "2.6.5", + }, + Object { + "releaseTimestamp": "2018-06-07T15:24:16.807Z", + "version": "2.6.6", + }, + Object { + "releaseTimestamp": "2018-07-07T15:41:32.657Z", + "version": "2.6.7", + }, + Object { + "releaseTimestamp": "2018-08-10T20:45:24.080Z", + "version": "2.7.0", + }, + Object { + "releaseTimestamp": "2019-08-21T07:08:49.360Z", + "version": "2.7.1", + }, + Object { + "releaseTimestamp": "2014-09-23T03:11:33.430Z", + "version": "3.0.0-alpha", + }, + Object { + "releaseTimestamp": "2014-11-03T06:24:59.217Z", + "version": "3.0.0-alpha-2", + }, + Object { + "releaseTimestamp": "2014-11-29T22:38:18.493Z", + "version": "3.0.0-alpha-3", + }, + Object { + "releaseTimestamp": "2014-12-31T04:47:39.507Z", + "version": "3.0.0-alpha-4", + }, + Object { + "releaseTimestamp": "2015-01-31T22:13:01.997Z", + "version": "3.0.0-alpha-5", + }, + Object { + "releaseTimestamp": "2015-03-26T11:33:22.173Z", + "version": "3.0.0-beta-1", + }, + Object { + "releaseTimestamp": "2015-05-13T00:51:22.430Z", + "version": "3.0.0-beta-2", + }, + Object { + "releaseTimestamp": "2015-07-15T23:44:47.403Z", + "version": "3.0.0-beta-3", + }, + Object { + "releaseTimestamp": "2015-08-25T23:24:11.473Z", + "version": "3.0.0-beta-4", + }, + Object { + "releaseTimestamp": "2015-10-17T03:39:18.100Z", + "version": "3.0.0-beta-5", + }, + Object { + "releaseTimestamp": "2015-11-01T21:56:49.637Z", + "version": "3.0.0-rc", + }, + Object { + "releaseTimestamp": "2015-11-08T16:27:15.110Z", + "version": "3.0.0-rc-2", + }, + Object { + "releaseTimestamp": "2015-11-14T05:30:57.323Z", + "version": "3.0.0-rc-3", + }, + Object { + "releaseTimestamp": "2015-11-16T00:02:51.807Z", + "version": "3.0.0", + }, + Object { + "releaseTimestamp": "2015-12-02T03:52:57.997Z", + "version": "3.0.1", + }, + Object { + "releaseTimestamp": "2016-03-05T21:12:58.990Z", + "version": "3.2.0", + }, + Object { + "releaseTimestamp": "2016-04-19T15:31:13.390Z", + "version": "3.2.1", + }, + Object { + "releaseTimestamp": "2016-06-25T17:44:56.253Z", + "version": "3.4.0", + }, + Object { + "releaseTimestamp": "2016-06-30T21:20:49.497Z", + "version": "3.4.1", + }, + Object { + "releaseTimestamp": "2016-10-04T01:19:19.447Z", + "version": "3.5.0", + }, + Object { + "releaseTimestamp": "2017-01-10T02:17:19.187Z", + "version": "3.6.0", + }, + Object { + "releaseTimestamp": "2017-02-26T14:56:04.407Z", + "version": "3.6.1", + }, + Object { + "releaseTimestamp": "2017-05-30T00:07:36.707Z", + "version": "3.7.0", + }, + Object { + "releaseTimestamp": "2017-06-06T01:59:11.787Z", + "version": "3.7.1", + }, + Object { + "releaseTimestamp": "2017-08-28T00:08:29.500Z", + "version": "3.8.0", + }, + Object { + "releaseTimestamp": "2017-08-29T01:11:58.860Z", + "version": "3.8.1", + }, + Object { + "releaseTimestamp": "2017-11-10T23:35:19.670Z", + "version": "3.9.0", + }, + Object { + "releaseTimestamp": "2018-03-13T00:29:56.400Z", + "version": "3.10.0", + }, + Object { + "releaseTimestamp": "2018-03-13T03:13:09.930Z", + "version": "3.10.1", + }, + Object { + "releaseTimestamp": "2018-10-07T01:17:31.310Z", + "version": "3.11.0", + }, + Object { + "releaseTimestamp": "2019-05-15T00:24:28.390Z", + "version": "3.12.0", + }, + ], +} +`; + +exports[`datasource/nuget/index getReleases processes real data (v3) nuspec fetch 404 error 2`] = ` +Array [ + Object { + "headers": Object { + "accept": "application/json", + "accept-encoding": "gzip, deflate, br", + "host": "api.nuget.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://api.nuget.org/v3/index.json", + }, + Object { + "headers": Object { + "accept": "application/json", + "accept-encoding": "gzip, deflate, br", + "host": "api.nuget.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://api.nuget.org/v3/registration5-gz-semver2/nunit/index.json", + }, + Object { + "headers": Object { + "accept": "application/json", + "accept-encoding": "gzip, deflate, br", + "host": "api.nuget.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://api.nuget.org/v3/index.json", + }, + Object { + "headers": Object { + "accept-encoding": "gzip, deflate, br", + "host": "api.nuget.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://api.nuget.org/v3-flatcontainer/nunit/3.12.0/nunit.nuspec", + }, +] +`; + +exports[`datasource/nuget/index getReleases processes real data (v3) nuspec fetch error 1`] = ` +Object { + "registryUrl": "https://api.nuget.org/v3/index.json", + "releases": Array [ + Object { + "releaseTimestamp": "2011-01-07T07:57:55.387Z", + "version": "2.5.7.10213", + }, + Object { + "releaseTimestamp": "2011-02-09T07:26:34.347Z", + "version": "2.5.9.10348", + }, + Object { + "releaseTimestamp": "2011-04-25T20:20:34.397Z", + "version": "2.5.10.11092", + }, + Object { + "isDeprecated": true, + "releaseTimestamp": "1900-01-01T00:00:00.000Z", + "version": "2.6.0.12051", + }, + Object { + "releaseTimestamp": "2012-02-24T04:03:05.290Z", + "version": "2.6.0.12054", + }, + Object { + "releaseTimestamp": "2012-08-05T03:08:28.403Z", + "version": "2.6.1", + }, + Object { + "releaseTimestamp": "2012-10-23T15:37:48.000Z", + "version": "2.6.2", + }, + Object { + "releaseTimestamp": "2013-10-11T01:52:53.417Z", + "version": "2.6.3", + }, + Object { + "releaseTimestamp": "2014-12-17T17:30:47.607Z", + "version": "2.6.4", + }, + Object { + "releaseTimestamp": "2018-04-20T04:23:59.217Z", + "version": "2.6.5", + }, + Object { + "releaseTimestamp": "2018-06-07T15:24:16.807Z", + "version": "2.6.6", + }, + Object { + "releaseTimestamp": "2018-07-07T15:41:32.657Z", + "version": "2.6.7", + }, + Object { + "releaseTimestamp": "2018-08-10T20:45:24.080Z", + "version": "2.7.0", + }, + Object { + "releaseTimestamp": "2019-08-21T07:08:49.360Z", + "version": "2.7.1", + }, + Object { + "releaseTimestamp": "2014-09-23T03:11:33.430Z", + "version": "3.0.0-alpha", + }, + Object { + "releaseTimestamp": "2014-11-03T06:24:59.217Z", + "version": "3.0.0-alpha-2", + }, + Object { + "releaseTimestamp": "2014-11-29T22:38:18.493Z", + "version": "3.0.0-alpha-3", + }, + Object { + "releaseTimestamp": "2014-12-31T04:47:39.507Z", + "version": "3.0.0-alpha-4", + }, + Object { + "releaseTimestamp": "2015-01-31T22:13:01.997Z", + "version": "3.0.0-alpha-5", + }, + Object { + "releaseTimestamp": "2015-03-26T11:33:22.173Z", + "version": "3.0.0-beta-1", + }, + Object { + "releaseTimestamp": "2015-05-13T00:51:22.430Z", + "version": "3.0.0-beta-2", + }, + Object { + "releaseTimestamp": "2015-07-15T23:44:47.403Z", + "version": "3.0.0-beta-3", + }, + Object { + "releaseTimestamp": "2015-08-25T23:24:11.473Z", + "version": "3.0.0-beta-4", + }, + Object { + "releaseTimestamp": "2015-10-17T03:39:18.100Z", + "version": "3.0.0-beta-5", + }, + Object { + "releaseTimestamp": "2015-11-01T21:56:49.637Z", + "version": "3.0.0-rc", + }, + Object { + "releaseTimestamp": "2015-11-08T16:27:15.110Z", + "version": "3.0.0-rc-2", + }, + Object { + "releaseTimestamp": "2015-11-14T05:30:57.323Z", + "version": "3.0.0-rc-3", + }, + Object { + "releaseTimestamp": "2015-11-16T00:02:51.807Z", + "version": "3.0.0", + }, + Object { + "releaseTimestamp": "2015-12-02T03:52:57.997Z", + "version": "3.0.1", + }, + Object { + "releaseTimestamp": "2016-03-05T21:12:58.990Z", + "version": "3.2.0", + }, + Object { + "releaseTimestamp": "2016-04-19T15:31:13.390Z", + "version": "3.2.1", + }, + Object { + "releaseTimestamp": "2016-06-25T17:44:56.253Z", + "version": "3.4.0", + }, + Object { + "releaseTimestamp": "2016-06-30T21:20:49.497Z", + "version": "3.4.1", + }, + Object { + "releaseTimestamp": "2016-10-04T01:19:19.447Z", + "version": "3.5.0", + }, + Object { + "releaseTimestamp": "2017-01-10T02:17:19.187Z", + "version": "3.6.0", + }, + Object { + "releaseTimestamp": "2017-02-26T14:56:04.407Z", + "version": "3.6.1", + }, + Object { + "releaseTimestamp": "2017-05-30T00:07:36.707Z", + "version": "3.7.0", + }, + Object { + "releaseTimestamp": "2017-06-06T01:59:11.787Z", + "version": "3.7.1", + }, + Object { + "releaseTimestamp": "2017-08-28T00:08:29.500Z", + "version": "3.8.0", + }, + Object { + "releaseTimestamp": "2017-08-29T01:11:58.860Z", + "version": "3.8.1", + }, + Object { + "releaseTimestamp": "2017-11-10T23:35:19.670Z", + "version": "3.9.0", + }, + Object { + "releaseTimestamp": "2018-03-13T00:29:56.400Z", + "version": "3.10.0", + }, + Object { + "releaseTimestamp": "2018-03-13T03:13:09.930Z", + "version": "3.10.1", + }, + Object { + "releaseTimestamp": "2018-10-07T01:17:31.310Z", + "version": "3.11.0", + }, + Object { + "releaseTimestamp": "2019-05-15T00:24:28.390Z", + "version": "3.12.0", + }, + ], +} +`; + +exports[`datasource/nuget/index getReleases processes real data (v3) nuspec fetch error 2`] = ` +Array [ + Object { + "headers": Object { + "accept": "application/json", + "accept-encoding": "gzip, deflate, br", + "host": "api.nuget.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://api.nuget.org/v3/index.json", + }, + Object { + "headers": Object { + "accept": "application/json", + "accept-encoding": "gzip, deflate, br", + "host": "api.nuget.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://api.nuget.org/v3/registration5-gz-semver2/nunit/index.json", + }, + Object { + "headers": Object { + "accept": "application/json", + "accept-encoding": "gzip, deflate, br", + "host": "api.nuget.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://api.nuget.org/v3/index.json", + }, + Object { + "headers": Object { + "accept-encoding": "gzip, deflate, br", + "host": "api.nuget.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://api.nuget.org/v3-flatcontainer/nunit/3.12.0/nunit.nuspec", + }, +] +`; + exports[`datasource/nuget/index getReleases processes real data no relase (v2) 1`] = ` Array [ Object { diff --git a/lib/datasource/nuget/index.spec.ts b/lib/datasource/nuget/index.spec.ts index e741bd6e55..3ed42025a9 100644 --- a/lib/datasource/nuget/index.spec.ts +++ b/lib/datasource/nuget/index.spec.ts @@ -435,6 +435,42 @@ describe(getName(), () => { expect(httpMock.getTrace()).toMatchSnapshot(); expect(res.sourceUrl).toBeDefined(); }); + it('processes real data (v3) nuspec fetch error', async () => { + httpMock + .scope('https://api.nuget.org') + .get('/v3/index.json') + .twice() + .reply(200, JSON.parse(nugetIndexV3)) + .get('/v3/registration5-gz-semver2/nunit/index.json') + .reply(200, pkgListV3Registration) + .get('/v3-flatcontainer/nunit/3.12.0/nunit.nuspec') + .replyWithError('unknown'); + const res = await getPkgReleases({ + ...configV3, + }); + expect(res).not.toBeNull(); + expect(res).toMatchSnapshot(); + expect(res.sourceUrl).not.toBeDefined(); + expect(httpMock.getTrace()).toMatchSnapshot(); + }); + it('processes real data (v3) nuspec fetch 404 error', async () => { + httpMock + .scope('https://api.nuget.org') + .get('/v3/index.json') + .twice() + .reply(200, JSON.parse(nugetIndexV3)) + .get('/v3/registration5-gz-semver2/nunit/index.json') + .reply(200, pkgListV3Registration) + .get('/v3-flatcontainer/nunit/3.12.0/nunit.nuspec') + .reply(404); + const res = await getPkgReleases({ + ...configV3, + }); + expect(res).not.toBeNull(); + expect(res).toMatchSnapshot(); + expect(res.sourceUrl).not.toBeDefined(); + expect(httpMock.getTrace()).toMatchSnapshot(); + }); it('processes real data (v2)', async () => { httpMock .scope('https://www.nuget.org') diff --git a/lib/datasource/nuget/v3.ts b/lib/datasource/nuget/v3.ts index 364318bd8e..9339effb4a 100644 --- a/lib/datasource/nuget/v3.ts +++ b/lib/datasource/nuget/v3.ts @@ -173,7 +173,7 @@ export async function getReleases( dep.sourceUrl = sourceUrl; } } - } catch (err) /* istanbul ignore next */ { + } catch (err) { // ignore / silence 404. Seen on proget, if remote connector is used and package is not yet cached if (err instanceof HttpError && err.response?.statusCode === 404) { logger.debug( -- GitLab