diff --git a/lib/datasource/docker/index.ts b/lib/datasource/docker/index.ts index cdff0f0af77de8..9ab3c01480fad5 100644 --- a/lib/datasource/docker/index.ts +++ b/lib/datasource/docker/index.ts @@ -465,15 +465,6 @@ async function getTags( } } -export function getConfigResponse( - url: string, - headers: OutgoingHttpHeaders -): Promise { - return http.get(url, { - headers, - }); -} - /* * docker.getLabels * @@ -535,7 +526,9 @@ async function getLabels( return {}; } const url = `${registry}/v2/${repository}/blobs/${configDigest}`; - const configResponse = await getConfigResponse(url, headers); + const configResponse = await http.get(url, { + headers, + }); labels = JSON.parse(configResponse.body).config.Labels; if (labels) { diff --git a/lib/manager/bazel/__snapshots__/update.spec.ts.snap b/lib/manager/bazel/__snapshots__/update.spec.ts.snap index 125e98d178764b..b154600f56ee18 100644 --- a/lib/manager/bazel/__snapshots__/update.spec.ts.snap +++ b/lib/manager/bazel/__snapshots__/update.spec.ts.snap @@ -124,6 +124,20 @@ container_pull( " `; +exports[`manager/bazel/update updateDependency updates commit-based http archive 1`] = ` +Array [ + Object { + "headers": Object { + "accept-encoding": "gzip, deflate", + "host": "github.com", + "user-agent": "got/9.6.0 (https://github.com/sindresorhus/got)", + }, + "method": "GET", + "url": "https://github.com/GoogleContainerTools/distroless/archive/033387ac8853e6cc1cd47df6c346bc53cbc490d8.tar.gz", + }, +] +`; + exports[`manager/bazel/update updateDependency updates container_pull deptype and prserves comment 1`] = ` "container_pull( name=\\"hasura\\", @@ -135,3 +149,54 @@ exports[`manager/bazel/update updateDependency updates container_pull deptype an ) " `; + +exports[`manager/bazel/update updateDependency updates finds url instead of urls 1`] = ` +Array [ + Object { + "headers": Object { + "accept-encoding": "gzip, deflate", + "host": "github.com", + "user-agent": "got/9.6.0 (https://github.com/sindresorhus/got)", + }, + "method": "GET", + "url": "https://github.com/bazelbuild/bazel-skylib/archive/0.8.0.tar.gz", + }, +] +`; + +exports[`manager/bazel/update updateDependency updates http archive with content other then WORKSPACE 1`] = ` +Array [ + Object { + "headers": Object { + "accept-encoding": "gzip, deflate", + "host": "github.com", + "user-agent": "got/9.6.0 (https://github.com/sindresorhus/got)", + }, + "method": "GET", + "url": "https://github.com/bazelbuild/bazel-skylib/archive/0.8.0.tar.gz", + }, +] +`; + +exports[`manager/bazel/update updateDependency updates http_archive with urls array 1`] = ` +Array [ + Object { + "headers": Object { + "accept-encoding": "gzip, deflate", + "host": "mirror.bazel.build", + "user-agent": "got/9.6.0 (https://github.com/sindresorhus/got)", + }, + "method": "GET", + "url": "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/archive/0.6.2.tar.gz", + }, + Object { + "headers": Object { + "accept-encoding": "gzip, deflate", + "host": "github.com", + "user-agent": "got/9.6.0 (https://github.com/sindresorhus/got)", + }, + "method": "GET", + "url": "https://github.com/bazelbuild/bazel-skylib/archive/0.6.2.tar.gz", + }, +] +`; diff --git a/lib/manager/bazel/update.spec.ts b/lib/manager/bazel/update.spec.ts index 8ababd1faa9965..acbde7e323759e 100644 --- a/lib/manager/bazel/update.spec.ts +++ b/lib/manager/bazel/update.spec.ts @@ -1,14 +1,10 @@ import { readFileSync } from 'fs'; import { resolve } from 'path'; -import { fromStream as _fromStream } from 'hasha'; +import { Readable } from 'stream'; +import * as httpMock from '../../../test/httpMock'; import { UpdateType } from '../../config'; import { updateDependency } from './update'; -jest.mock('hasha'); -jest.mock('../../util/got'); - -const fromStream: jest.Mock> = _fromStream as any; - const content = readFileSync( resolve('lib/manager/bazel/__fixtures__/WORKSPACE1'), 'utf8' @@ -36,7 +32,13 @@ describe('manager/bazel/update', () => { describe('updateDependency', () => { beforeEach(() => { jest.resetAllMocks(); + httpMock.setup(); }); + + afterEach(() => { + httpMock.reset(); + }); + it('updates tag', async () => { const upgrade = { depName: 'build_bazel_rules_nodejs', @@ -122,12 +124,18 @@ describe('manager/bazel/update', () => { }, newDigest: '033387ac8853e6cc1cd47df6c346bc53cbc490d8', }; - fromStream.mockResolvedValueOnce('abc123'); + httpMock + .scope('https://github.com') + .get( + '/GoogleContainerTools/distroless/archive/033387ac8853e6cc1cd47df6c346bc53cbc490d8.tar.gz' + ) + .reply(200, Readable.from(['foo'])); const res = await updateDependency({ fileContent: content, upgrade, }); expect(res).not.toEqual(content); + expect(httpMock.getTrace()).toMatchSnapshot(); }); it('updates http archive with content other then WORKSPACE', async () => { const upgrade = { @@ -145,13 +153,17 @@ describe('manager/bazel/update', () => { currentValue: '0.6.0', newValue: '0.8.0', }; - fromStream.mockResolvedValueOnce('abc123'); + httpMock + .scope('https://github.com') + .get('/bazelbuild/bazel-skylib/archive/0.8.0.tar.gz') + .reply(200, Readable.from(['foo'])); const res = await updateDependency({ fileContent: content, upgrade, }); expect(res).not.toEqual(fileWithBzlExtension); expect(res.indexOf('0.8.0')).not.toBe(-1); + expect(httpMock.getTrace()).toMatchSnapshot(); }); it('updates finds url instead of urls', async () => { const upgrade = { @@ -169,13 +181,17 @@ describe('manager/bazel/update', () => { currentValue: '0.6.0', newValue: '0.8.0', }; - fromStream.mockResolvedValueOnce('abc123'); + httpMock + .scope('https://github.com') + .get('/bazelbuild/bazel-skylib/archive/0.8.0.tar.gz') + .reply(200, Readable.from(['foo'])); const res = await updateDependency({ fileContent: content, upgrade, }); expect(res).not.toEqual(fileWithBzlExtension); expect(res.indexOf('0.8.0')).not.toBe(-1); + expect(httpMock.getTrace()).toMatchSnapshot(); }); it('returns null if no urls resolve hashes', async () => { const upgrade = { @@ -217,7 +233,6 @@ http_archive( currentValue: '0.5.0', newValue: '0.6.2', }; - fromStream.mockResolvedValueOnce('abc123'); const res = await updateDependency({ fileContent: content, upgrade, @@ -246,7 +261,14 @@ http_archive( currentValue: '0.5.0', newValue: '0.6.2', }; - fromStream.mockResolvedValueOnce('abc123'); + httpMock + .scope('https://github.com') + .get('/bazelbuild/bazel-skylib/archive/0.6.2.tar.gz') + .reply(200, Readable.from(['foo'])); + httpMock + .scope('https://mirror.bazel.build') + .get('/github.com/bazelbuild/bazel-skylib/archive/0.6.2.tar.gz') + .reply(200, Readable.from(['foo'])); const res = await updateDependency({ fileContent: content, upgrade, @@ -254,6 +276,7 @@ http_archive( expect(res).not.toEqual(content); expect(res.indexOf('0.5.0')).toBe(-1); expect(res.indexOf('0.6.2')).not.toBe(-1); + expect(httpMock.getTrace()).toMatchSnapshot(); }); }); }); diff --git a/lib/manager/homebrew/__snapshots__/update.spec.ts.snap b/lib/manager/homebrew/__snapshots__/update.spec.ts.snap index e673acfcb3da97..3a1bc4003ce480 100644 --- a/lib/manager/homebrew/__snapshots__/update.spec.ts.snap +++ b/lib/manager/homebrew/__snapshots__/update.spec.ts.snap @@ -63,6 +63,154 @@ end " `; +exports[`manager/homebrew/update returns unchanged content if both got requests fail 2`] = ` +Array [ + Object { + "headers": Object { + "accept-encoding": "gzip, deflate", + "host": "github.com", + "user-agent": "got/9.6.0 (https://github.com/sindresorhus/got)", + }, + "method": "GET", + "url": "https://github.com/aide/aide/releases/download/v0.17.7/aide-0.17.7.tar.gz", + }, + Object { + "headers": Object { + "accept-encoding": "gzip, deflate", + "host": "github.com", + "user-agent": "got/9.6.0 (https://github.com/sindresorhus/got)", + }, + "method": "GET", + "url": "https://github.com/aide/aide/archive/v0.17.7.tar.gz", + }, +] +`; + +exports[`manager/homebrew/update returns unchanged content if fromStream promise rejects 1`] = ` +Array [ + Object { + "headers": Object { + "accept-encoding": "gzip, deflate", + "host": "github.com", + "user-agent": "got/9.6.0 (https://github.com/sindresorhus/got)", + }, + "method": "GET", + "url": "https://github.com/bazelbuild/bazel-watcher/releases/download/v0.9.3/bazel-watcher-0.9.3.tar.gz", + }, + Object { + "headers": Object { + "accept-encoding": "gzip, deflate", + "host": "github.com", + "user-agent": "got/9.6.0 (https://github.com/sindresorhus/got)", + }, + "method": "GET", + "url": "https://github.com/bazelbuild/bazel-watcher/archive/v0.9.3.tar.gz", + }, +] +`; + +exports[`manager/homebrew/update returns unchanged content if repoName in upgrade object is invalid 1`] = ` +Array [ + Object { + "headers": Object { + "accept-encoding": "gzip, deflate", + "host": "github.com", + "user-agent": "got/9.6.0 (https://github.com/sindresorhus/got)", + }, + "method": "GET", + "url": "https://github.com/bazelbuild/invalid/repo/name/releases/download/v0.9.3/invalid/repo/name-0.9.3.tar.gz", + }, + Object { + "headers": Object { + "accept-encoding": "gzip, deflate", + "host": "github.com", + "user-agent": "got/9.6.0 (https://github.com/sindresorhus/got)", + }, + "method": "GET", + "url": "https://github.com/bazelbuild/invalid/repo/name/archive/v0.9.3.tar.gz", + }, +] +`; + +exports[`manager/homebrew/update returns unchanged content if repoName in upgrade object is wrong 1`] = ` +Array [ + Object { + "headers": Object { + "accept-encoding": "gzip, deflate", + "host": "github.com", + "user-agent": "got/9.6.0 (https://github.com/sindresorhus/got)", + }, + "method": "GET", + "url": "https://github.com/bazelbuild/wrong-version/archive/v10.2.3.tar.gz/releases/download/v0.9.3/wrong-version/archive/v10.2.3.tar.gz-0.9.3.tar.gz", + }, + Object { + "headers": Object { + "accept-encoding": "gzip, deflate", + "host": "github.com", + "user-agent": "got/9.6.0 (https://github.com/sindresorhus/got)", + }, + "method": "GET", + "url": "https://github.com/bazelbuild/wrong-version/archive/v10.2.3.tar.gz/archive/v0.9.3.tar.gz", + }, +] +`; + +exports[`manager/homebrew/update returns unchanged content if sha256 field in Formula file is invalid 1`] = ` +Array [ + Object { + "headers": Object { + "accept-encoding": "gzip, deflate", + "host": "github.com", + "user-agent": "got/9.6.0 (https://github.com/sindresorhus/got)", + }, + "method": "GET", + "url": "https://github.com/bazelbuild/bazel-watcher/releases/download/v0.9.3/bazel-watcher-0.9.3.tar.gz", + }, +] +`; + +exports[`manager/homebrew/update returns unchanged content if sha256 field in Formula file is missing 1`] = ` +Array [ + Object { + "headers": Object { + "accept-encoding": "gzip, deflate", + "host": "github.com", + "user-agent": "got/9.6.0 (https://github.com/sindresorhus/got)", + }, + "method": "GET", + "url": "https://github.com/bazelbuild/bazel-watcher/releases/download/v0.9.3/bazel-watcher-0.9.3.tar.gz", + }, +] +`; + +exports[`manager/homebrew/update returns unchanged content if url field in Formula file is invalid 1`] = ` +Array [ + Object { + "headers": Object { + "accept-encoding": "gzip, deflate", + "host": "github.com", + "user-agent": "got/9.6.0 (https://github.com/sindresorhus/got)", + }, + "method": "GET", + "url": "https://github.com/bazelbuild/bazel-watcher/releases/download/v0.9.3/bazel-watcher-0.9.3.tar.gz", + }, +] +`; + +exports[`manager/homebrew/update returns unchanged content if url field in Formula file is missing 1`] = ` +Array [ + Object { + "headers": Object { + "accept-encoding": "gzip, deflate", + "host": "github.com", + "user-agent": "got/9.6.0 (https://github.com/sindresorhus/got)", + }, + "method": "GET", + "url": "https://github.com/bazelbuild/bazel-watcher/releases/download/v0.9.3/bazel-watcher-0.9.3.tar.gz", + }, +] +`; + exports[`manager/homebrew/update updates "archive" github dependency 1`] = ` "# Copyright 2018 The Bazel Authors. All rights reserved. # @@ -93,7 +241,7 @@ class Ibazel < Formula # To generate run: # curl https://codeload.github.com/bazelbuild/bazel-watcher/tar.gz/v0.8.2 | sha256sum - sha256 'new_hash_value' + sha256 '2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae' bottle :unneeded @@ -114,6 +262,20 @@ end " `; +exports[`manager/homebrew/update updates "archive" github dependency 2`] = ` +Array [ + Object { + "headers": Object { + "accept-encoding": "gzip, deflate", + "host": "github.com", + "user-agent": "got/9.6.0 (https://github.com/sindresorhus/got)", + }, + "method": "GET", + "url": "https://github.com/bazelbuild/bazel-watcher/releases/download/v0.9.3/bazel-watcher-0.9.3.tar.gz", + }, +] +`; + exports[`manager/homebrew/update updates "releases" github dependency 1`] = ` "=begin url \\"https://github.com/aide/aide/releases/download/v0.16.1/aide-0.16.1.tar.gz\\" @@ -127,7 +289,7 @@ class Aide < Formula desc \\"File and directory integrity checker\\" homepage \\"https://aide.github.io/\\" url \\"https://github.com/aide/aide/releases/download/v0.17.7/aide-0.17.7.tar.gz\\" - sha256 \\"new_hash_value\\" + sha256 \\"2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae\\" bottle do cellar :any @@ -176,3 +338,17 @@ class Aide < Formula end " `; + +exports[`manager/homebrew/update updates "releases" github dependency 2`] = ` +Array [ + Object { + "headers": Object { + "accept-encoding": "gzip, deflate", + "host": "github.com", + "user-agent": "got/9.6.0 (https://github.com/sindresorhus/got)", + }, + "method": "GET", + "url": "https://github.com/aide/aide/releases/download/v0.17.7/aide-0.17.7.tar.gz", + }, +] +`; diff --git a/lib/manager/homebrew/update.spec.ts b/lib/manager/homebrew/update.spec.ts index 38c4e0c2b99fd8..296c15fab72cce 100644 --- a/lib/manager/homebrew/update.spec.ts +++ b/lib/manager/homebrew/update.spec.ts @@ -1,12 +1,8 @@ import fs from 'fs'; -import { fromStream as _fromStream } from 'hasha'; +import { Readable } from 'stream'; +import * as httpMock from '../../../test/httpMock'; import { updateDependency } from './update'; -jest.mock('hasha'); -jest.mock('../../util/got'); - -const fromStream: jest.Mock> = _fromStream as any; - const aide = fs.readFileSync( 'lib/manager/homebrew/__fixtures__/aide.rb', 'utf8' @@ -16,10 +12,19 @@ const ibazel = fs.readFileSync( 'utf8' ); +const baseUrl = 'https://github.com'; + describe('manager/homebrew/update', () => { beforeEach(() => { jest.resetAllMocks(); + jest.resetModules(); + httpMock.setup(); }); + + afterEach(() => { + httpMock.reset(); + }); + it('updates "releases" github dependency', async () => { const upgrade = { currentValue: 'v0.16.1', @@ -34,7 +39,10 @@ describe('manager/homebrew/update', () => { }, newValue: 'v0.17.7', }; - fromStream.mockResolvedValueOnce('new_hash_value'); + httpMock + .scope(baseUrl) + .get('/aide/aide/releases/download/v0.17.7/aide-0.17.7.tar.gz') + .reply(200, Readable.from(['foo'])); const newContent = await updateDependency({ fileContent: aide, upgrade, @@ -42,6 +50,7 @@ describe('manager/homebrew/update', () => { expect(newContent).not.toBeNull(); expect(newContent).not.toBe(aide); expect(newContent).toMatchSnapshot(); + expect(httpMock.getTrace()).toMatchSnapshot(); }); it('updates "archive" github dependency', async () => { const upgrade = { @@ -57,7 +66,12 @@ describe('manager/homebrew/update', () => { }, newValue: 'v0.9.3', }; - fromStream.mockResolvedValueOnce('new_hash_value'); + httpMock + .scope(baseUrl) + .get( + '/bazelbuild/bazel-watcher/releases/download/v0.9.3/bazel-watcher-0.9.3.tar.gz' + ) + .reply(200, Readable.from(['foo'])); const newContent = await updateDependency({ fileContent: ibazel, upgrade, @@ -65,6 +79,7 @@ describe('manager/homebrew/update', () => { expect(newContent).not.toBeNull(); expect(newContent).not.toBe(ibazel); expect(newContent).toMatchSnapshot(); + expect(httpMock.getTrace()).toMatchSnapshot(); }); it('returns unchanged content if fromStream promise rejects', async () => { const upgrade = { @@ -80,13 +95,21 @@ describe('manager/homebrew/update', () => { }, newValue: 'v0.9.3', }; - fromStream.mockRejectedValueOnce('Request failed'); + httpMock + .scope(baseUrl) + .get( + '/bazelbuild/bazel-watcher/releases/download/v0.9.3/bazel-watcher-0.9.3.tar.gz' + ) + .replyWithError('') + .get('/bazelbuild/bazel-watcher/archive/v0.9.3.tar.gz') + .replyWithError(''); const newContent = await updateDependency({ fileContent: ibazel, upgrade, }); expect(newContent).not.toBeNull(); expect(newContent).toBe(ibazel); + expect(httpMock.getTrace()).toMatchSnapshot(); }); it('returns unchanged content if url field in upgrade object is invalid', async () => { const content = ibazel; @@ -102,7 +125,6 @@ describe('manager/homebrew/update', () => { }, newValue: 'v0.9.3', }; - fromStream.mockResolvedValueOnce('some_content'); const newContent = await updateDependency({ fileContent: content, upgrade, @@ -125,15 +147,21 @@ describe('manager/homebrew/update', () => { }, newValue: 'v0.9.3', }; - fromStream - .mockRejectedValueOnce('Request failed') - .mockResolvedValueOnce('some_content'); + httpMock + .scope(baseUrl) + .get( + '/bazelbuild/invalid/repo/name/releases/download/v0.9.3/invalid/repo/name-0.9.3.tar.gz' + ) + .replyWithError('') + .get('/bazelbuild/invalid/repo/name/archive/v0.9.3.tar.gz') + .reply(200, Readable.from(['foo'])); const newContent = await updateDependency({ fileContent: content, upgrade, }); expect(newContent).not.toBeNull(); expect(newContent).toBe(content); + expect(httpMock.getTrace()).toMatchSnapshot(); }); it('returns unchanged content if repoName in upgrade object is wrong', async () => { const content = ibazel; @@ -150,15 +178,23 @@ describe('manager/homebrew/update', () => { }, newValue: 'v0.9.3', }; - fromStream - .mockRejectedValueOnce('Request failed') - .mockResolvedValueOnce('some_content'); + httpMock + .scope(baseUrl) + .get( + '/bazelbuild/wrong-version/archive/v10.2.3.tar.gz/releases/download/v0.9.3/wrong-version/archive/v10.2.3.tar.gz-0.9.3.tar.gz' + ) + .replyWithError('') + .get( + '/bazelbuild/wrong-version/archive/v10.2.3.tar.gz/archive/v0.9.3.tar.gz' + ) + .reply(200, Readable.from(['foo'])); const newContent = await updateDependency({ fileContent: content, upgrade, }); expect(newContent).not.toBeNull(); expect(newContent).toBe(content); + expect(httpMock.getTrace()).toMatchSnapshot(); }); it('returns unchanged content if url field in Formula file is invalid', async () => { const content = ` @@ -182,13 +218,19 @@ describe('manager/homebrew/update', () => { }, newValue: 'v0.9.3', }; - fromStream.mockResolvedValueOnce('some_content'); + httpMock + .scope(baseUrl) + .get( + '/bazelbuild/bazel-watcher/releases/download/v0.9.3/bazel-watcher-0.9.3.tar.gz' + ) + .reply(200, Readable.from(['foo'])); const newContent = await updateDependency({ fileContent: content, upgrade, }); expect(newContent).not.toBeNull(); expect(newContent).toBe(content); + expect(httpMock.getTrace()).toMatchSnapshot(); }); it('returns unchanged content if url field in Formula file is missing', async () => { const content = ` @@ -211,13 +253,19 @@ describe('manager/homebrew/update', () => { }, newValue: 'v0.9.3', }; - fromStream.mockResolvedValueOnce('some_content'); + httpMock + .scope(baseUrl) + .get( + '/bazelbuild/bazel-watcher/releases/download/v0.9.3/bazel-watcher-0.9.3.tar.gz' + ) + .reply(200, Readable.from(['foo'])); const newContent = await updateDependency({ fileContent: content, upgrade, }); expect(newContent).not.toBeNull(); expect(newContent).toBe(content); + expect(httpMock.getTrace()).toMatchSnapshot(); }); it('returns unchanged content if sha256 field in Formula file is invalid', async () => { const content = ` @@ -241,13 +289,19 @@ describe('manager/homebrew/update', () => { }, newValue: 'v0.9.3', }; - fromStream.mockResolvedValueOnce('some_content'); + httpMock + .scope(baseUrl) + .get( + '/bazelbuild/bazel-watcher/releases/download/v0.9.3/bazel-watcher-0.9.3.tar.gz' + ) + .reply(200, Readable.from(['foo'])); const newContent = await updateDependency({ fileContent: content, upgrade, }); expect(newContent).not.toBeNull(); expect(newContent).toBe(content); + expect(httpMock.getTrace()).toMatchSnapshot(); }); it('returns unchanged content if sha256 field in Formula file is missing', async () => { const content = ` @@ -270,13 +324,19 @@ describe('manager/homebrew/update', () => { }, newValue: 'v0.9.3', }; - fromStream.mockResolvedValueOnce('some_content'); + httpMock + .scope(baseUrl) + .get( + '/bazelbuild/bazel-watcher/releases/download/v0.9.3/bazel-watcher-0.9.3.tar.gz' + ) + .reply(200, Readable.from(['foo'])); const newContent = await updateDependency({ fileContent: content, upgrade, }); expect(newContent).not.toBeNull(); expect(newContent).toBe(content); + expect(httpMock.getTrace()).toMatchSnapshot(); }); it('returns unchanged content if both got requests fail', async () => { const upgrade = { @@ -292,9 +352,12 @@ describe('manager/homebrew/update', () => { }, newValue: 'v0.17.7', }; - fromStream - .mockRejectedValueOnce('Request failed.') - .mockRejectedValueOnce('Request failed.'); + httpMock + .scope(baseUrl) + .get('/aide/aide/releases/download/v0.17.7/aide-0.17.7.tar.gz') + .replyWithError('') + .get('/aide/aide/archive/v0.17.7.tar.gz') + .replyWithError(''); const newContent = await updateDependency({ fileContent: aide, upgrade, @@ -302,5 +365,6 @@ describe('manager/homebrew/update', () => { expect(newContent).not.toBeNull(); expect(newContent).toBe(aide); expect(newContent).toMatchSnapshot(); + expect(httpMock.getTrace()).toMatchSnapshot(); }); }); diff --git a/lib/manager/homebrew/update.ts b/lib/manager/homebrew/update.ts index 497bb6eb37a49f..3a62dbd628ab07 100644 --- a/lib/manager/homebrew/update.ts +++ b/lib/manager/homebrew/update.ts @@ -181,6 +181,7 @@ export async function updateDependency({ return fileContent; } } + // istanbul ignore next if (!newSha256) { logger.debug( `Failed to generate new sha256 for ${upgrade.depName} - update failed` diff --git a/lib/util/got/__snapshots__/index.spec.ts.snap b/lib/util/got/__snapshots__/index.spec.ts.snap deleted file mode 100644 index a07baa889b3cc3..00000000000000 --- a/lib/util/got/__snapshots__/index.spec.ts.snap +++ /dev/null @@ -1,92 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`util/got/index gets 1`] = ` -Object { - "body": Object {}, - "options": Object { - "baseUrl": "https://api.github.com/", - "cache": false, - "decompress": true, - "followRedirect": true, - "form": false, - "hash": "", - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "user-agent": "got/9.6.0 (https://github.com/sindresorhus/got)", - }, - "hooks": Object { - "afterResponse": Array [], - "beforeError": Array [], - "beforeRedirect": Array [], - "beforeRequest": Array [], - "beforeRetry": Array [], - "init": Array [], - }, - "hostType": "github", - "hostname": "api.github.com", - "href": "https://api.github.com/some", - "json": true, - "method": "GET", - "path": "/some", - "pathname": "/some", - "protocol": "https:", - "retry": Object { - "errorCodes": Set {}, - "methods": Set {}, - "retries": [Function], - "statusCodes": Set {}, - }, - "search": "", - "stream": false, - "throwHttpErrors": true, - "useCache": false, - "useElectronNet": false, - }, -} -`; - -exports[`util/got/index gets 2`] = ` -Object { - "body": Object {}, - "options": Object { - "baseUrl": "https://api.github.com/", - "cache": false, - "decompress": true, - "followRedirect": true, - "form": false, - "hash": "", - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "user-agent": "got/9.6.0 (https://github.com/sindresorhus/got)", - }, - "hooks": Object { - "afterResponse": Array [], - "beforeError": Array [], - "beforeRedirect": Array [], - "beforeRequest": Array [], - "beforeRetry": Array [], - "init": Array [], - }, - "hostType": "github", - "hostname": "api.github.com", - "href": "https://api.github.com/some", - "json": true, - "method": "HEAD", - "path": "/some", - "pathname": "/some", - "protocol": "https:", - "retry": Object { - "errorCodes": Set {}, - "methods": Set {}, - "retries": [Function], - "statusCodes": Set {}, - }, - "search": "", - "stream": false, - "throwHttpErrors": true, - "useElectronNet": false, - }, -} -`; diff --git a/lib/util/got/common.ts b/lib/util/got/common.ts deleted file mode 100644 index 3ae4b9bd875853..00000000000000 --- a/lib/util/got/common.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { Url } from 'url'; -import got from 'got'; - -export interface Options { - hooks?: any; - hostType?: string; - search?: string; - token?: string; - useCache?: boolean; -} - -export type GotJSONOptions = Options & got.GotJSONOptions; -export type GotStreamOptions = Options & got.GotOptions; - -export type GotUrl = string | Url; - -export interface GotFn { - ( - url: GotUrl, - options?: GotJSONOptions - ): got.GotPromise; - - ( - url: GotUrl, - options?: Options & got.GotBodyOptions - ): got.GotPromise; -} - -export interface Got - extends GotFn, - Record<'get' | 'post' | 'put' | 'patch' | 'head' | 'delete', GotFn> { - stream(url: GotUrl, options?: GotStreamOptions): NodeJS.ReadableStream; -} diff --git a/lib/util/got/got.spec.ts b/lib/util/got/got.spec.ts deleted file mode 100644 index 6820be0ac00025..00000000000000 --- a/lib/util/got/got.spec.ts +++ /dev/null @@ -1,70 +0,0 @@ -import nock from 'nock'; -import { getConfigResponse } from '../../datasource/docker'; - -// TODO: move to datasource/docker ? -describe('getConfigResponse', () => { - beforeEach(() => { - nock.disableNetConnect(); - }); - - afterEach(() => { - nock.cleanAll(); - nock.enableNetConnect(); - }); - - it('redirects correctly when the original and redirect url both have a port', async () => { - const url = - 'http://docker.registry.com:5000/v2/image:latest/blobs/some-digest'; - const redirectURL = - 'https://s3.aws.amazon.com:3000/docker/registry/v2/blobs/sha256/d4/some-digest/data?X-Amz-Algorithm=AWS4-HMAC-SHA256'; - nock('http://docker.registry.com:5000') - .get('/v2/image:latest/blobs/some-digest') - .reply(307, undefined, { - location: redirectURL, - }); - nock('https://s3.aws.amazon.com:3000') - .get( - '/docker/registry/v2/blobs/sha256/d4/some-digest/data?X-Amz-Algorithm=AWS4-HMAC-SHA256' - ) - .reply(200, 'test body'); - const response = await getConfigResponse(url, {}); - expect(response.body).toEqual('test body'); - }); - - it('redirects correctly when original url has a port, but the redirect url does not', async () => { - const url = - 'http://docker.registry.com:5001/v2/image:latest/blobs/some-digest'; - const redirectURL = - 'https://s3.aws.amazon.com/docker/registry/v2/blobs/sha256/d4/some-digest/data?X-Amz-Algorithm=AWS4-HMAC-SHA256'; - nock('http://docker.registry.com:5001') - .get('/v2/image:latest/blobs/some-digest') - .reply(307, undefined, { - location: redirectURL, - }); - nock('https://s3.aws.amazon.com') - .get( - '/docker/registry/v2/blobs/sha256/d4/some-digest/data?X-Amz-Algorithm=AWS4-HMAC-SHA256' - ) - .reply(200, 'test body'); - const response = await getConfigResponse(url, {}); - expect(response.body).toEqual('test body'); - }); - - it('redirects correctly when the original url does not have a port, but the redirect to url does', async () => { - const url = 'http://docker.registry.com/v2/image:latest/blobs/some-digest'; - const redirectURL = - 'https://s3.aws.amazon.com:3001/docker/registry/v2/blobs/sha256/d4/some-digest/data?X-Amz-Algorithm=AWS4-HMAC-SHA256'; - nock('http://docker.registry.com') - .get('/v2/image:latest/blobs/some-digest') - .reply(307, undefined, { - location: redirectURL, - }); - nock('https://s3.aws.amazon.com:3001') - .get( - '/docker/registry/v2/blobs/sha256/d4/some-digest/data?X-Amz-Algorithm=AWS4-HMAC-SHA256' - ) - .reply(200, 'test body'); - const response = await getConfigResponse(url, {}); - expect(response.body).toEqual('test body'); - }); -}); diff --git a/lib/util/got/index.spec.ts b/lib/util/got/index.spec.ts deleted file mode 100644 index 84bd8cf261bd2b..00000000000000 --- a/lib/util/got/index.spec.ts +++ /dev/null @@ -1,59 +0,0 @@ -import nock from 'nock'; -import { getName } from '../../../test/util'; -import { PLATFORM_TYPE_GITHUB } from '../../constants/platforms'; -import * as hostRules from '../host-rules'; -import { GotJSONOptions } from './common'; -import { api } from '.'; - -const baseUrl = 'https://api.github.com'; - -describe(getName(__filename), () => { - beforeEach(() => { - nock.disableNetConnect(); - }); - - afterEach(() => { - nock.cleanAll(); - hostRules.clear(); - nock.enableNetConnect(); - }); - - async function got(opts?: Partial) { - const { body, request } = (await api('some', { - method: 'GET', - baseUrl, - json: true, - ...opts, - })) as any; - return { body, options: request.gotOptions }; - } - - function mock(opts?: nock.Options, times = 1) { - return nock(baseUrl, opts).get('/some').times(times).reply(200, {}); - } - - it('gets', async () => { - const req = mock({}) - .head('/some') - .reply(200, {}) - .get('/some') - .replyWithError('not-found'); - - expect( - await got({ - hostType: PLATFORM_TYPE_GITHUB, - useCache: false, - }) - ).toMatchSnapshot(); - - expect( - await got({ hostType: PLATFORM_TYPE_GITHUB, method: 'HEAD' }) - ).toMatchSnapshot(); - - await expect(got({ hostType: PLATFORM_TYPE_GITHUB })).rejects.toThrow( - 'not-found' - ); - - expect(req.isDone()).toBe(true); - }); -}); diff --git a/lib/util/got/index.ts b/lib/util/got/index.ts deleted file mode 100644 index 4db3c23d40bfa3..00000000000000 --- a/lib/util/got/index.ts +++ /dev/null @@ -1,15 +0,0 @@ -import got from 'got'; -import { create, mergeInstances } from './util'; - -export * from './common'; - -const dummy = create({ - options: {}, - handler: (options, next) => { - return next(options); - }, -}); - -export const api = mergeInstances(got, dummy); - -export default api; diff --git a/lib/util/got/util.ts b/lib/util/got/util.ts deleted file mode 100644 index 8d476f54579fb2..00000000000000 --- a/lib/util/got/util.ts +++ /dev/null @@ -1,13 +0,0 @@ -import got from 'got'; -import { Got } from './common'; - -// TODO: missing types -export const mergeInstances = (got as any).mergeInstances as ( - ...args: got.GotInstance[] -) => Got; - -// TODO: missing types -export const create = (got as any).create as (defaults: { - options: any; - handler: Function; -}) => got.GotInstance; diff --git a/lib/util/http/index.ts b/lib/util/http/index.ts index 6358a65eede4a7..5b456e3bee2bff 100644 --- a/lib/util/http/index.ts +++ b/lib/util/http/index.ts @@ -1,8 +1,8 @@ import crypto from 'crypto'; import URL from 'url'; +import got from 'got'; import * as runCache from '../cache/run'; import { clone } from '../clone'; -import got from '../got'; import { applyAuthorization } from './auth'; import { applyHostRules } from './host-rules'; @@ -59,6 +59,9 @@ export class Http { hostType: this.hostType, ...httpOptions, }; + if (process.env.NODE_ENV === 'test') { + options.retry = 0; + } options.hooks = { beforeRedirect: [ (opts: any): void => {