From c3783171c265ef92d03929475a22915a19493f80 Mon Sep 17 00:00:00 2001 From: Richard Versteeg <rv2673@users.noreply.github.com> Date: Thu, 20 Jan 2022 20:55:10 +0100 Subject: [PATCH] fix(gitlab-packages): Add missing hostType for datasource calls (#13696) Co-authored-by: Rhys Arkins <rhys@arkins.net> --- lib/datasource/gitlab-packages/index.ts | 2 +- lib/util/http/host-rules.spec.ts | 79 +++++++++++++++++++++---- 2 files changed, 70 insertions(+), 11 deletions(-) diff --git a/lib/datasource/gitlab-packages/index.ts b/lib/datasource/gitlab-packages/index.ts index 2d36c15733..d767c59552 100644 --- a/lib/datasource/gitlab-packages/index.ts +++ b/lib/datasource/gitlab-packages/index.ts @@ -21,7 +21,7 @@ export class GitlabPackagesDatasource extends Datasource { constructor() { super(datasource); - this.http = new GitlabHttp(); + this.http = new GitlabHttp(datasource); } static getGitlabPackageApiUrl( diff --git a/lib/util/http/host-rules.spec.ts b/lib/util/http/host-rules.spec.ts index 00e04a386e..cad61c7a49 100644 --- a/lib/util/http/host-rules.spec.ts +++ b/lib/util/http/host-rules.spec.ts @@ -153,16 +153,75 @@ describe('util/http/host-rules', () => { `); }); + it('no fallback to gitlab', () => { + hostRules.add({ + hostType: 'gitlab-packages', + token: 'package-token', + }); + hostRules.add({ + hostType: 'gitlab-releases', + token: 'release-token', + }); + hostRules.add({ + hostType: 'gitlab-tags', + token: 'tags-token', + }); + expect( + applyHostRules(url, { ...options, hostType: 'gitlab-tags' }) + ).toEqual({ + context: { + authType: undefined, + }, + hostType: 'gitlab-tags', + token: 'tags-token', + }); + expect( + applyHostRules(url, { ...options, hostType: 'gitlab-releases' }) + ).toEqual({ + context: { + authType: undefined, + }, + hostType: 'gitlab-releases', + token: 'release-token', + }); + expect( + applyHostRules(url, { ...options, hostType: 'gitlab-packages' }) + ).toEqual({ + context: { + authType: undefined, + }, + hostType: 'gitlab-packages', + token: 'package-token', + }); + }); + it('fallback to gitlab', () => { - expect(applyHostRules(url, { ...options, hostType: 'gitlab-tags' })) - .toMatchInlineSnapshot(` - Object { - "context": Object { - "authType": undefined, - }, - "hostType": "gitlab-tags", - "token": "abc", - } - `); + expect( + applyHostRules(url, { ...options, hostType: 'gitlab-tags' }) + ).toEqual({ + context: { + authType: undefined, + }, + hostType: 'gitlab-tags', + token: 'abc', + }); + expect( + applyHostRules(url, { ...options, hostType: 'gitlab-releases' }) + ).toEqual({ + context: { + authType: undefined, + }, + hostType: 'gitlab-releases', + token: 'abc', + }); + expect( + applyHostRules(url, { ...options, hostType: 'gitlab-packages' }) + ).toEqual({ + context: { + authType: undefined, + }, + hostType: 'gitlab-packages', + token: 'abc', + }); }); }); -- GitLab