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: Remove 'util/got' #6523

Merged
merged 6 commits into from Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 3 additions & 10 deletions lib/datasource/docker/index.ts
Expand Up @@ -465,15 +465,6 @@ async function getTags(
}
}

export function getConfigResponse(
url: string,
headers: OutgoingHttpHeaders
): Promise<HttpResponse> {
return http.get(url, {
headers,
});
}

/*
* docker.getLabels
*
Expand Down Expand Up @@ -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) {
Expand Down
65 changes: 65 additions & 0 deletions lib/manager/bazel/__snapshots__/update.spec.ts.snap
Expand Up @@ -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\\",
Expand All @@ -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",
},
]
`;
45 changes: 34 additions & 11 deletions 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<Promise<string>> = _fromStream as any;

const content = readFileSync(
resolve('lib/manager/bazel/__fixtures__/WORKSPACE1'),
'utf8'
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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 = {
Expand All @@ -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 = {
Expand All @@ -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 = {
Expand Down Expand Up @@ -217,7 +233,6 @@ http_archive(
currentValue: '0.5.0',
newValue: '0.6.2',
};
fromStream.mockResolvedValueOnce('abc123');
const res = await updateDependency({
fileContent: content,
upgrade,
Expand Down Expand Up @@ -246,14 +261,22 @@ 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,
});
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();
});
});
});