From d93036b8abc5554329942754948ea8bed372dab6 Mon Sep 17 00:00:00 2001 From: Ricky Patel <rickyp@snowcoders.com> Date: Tue, 11 Feb 2020 14:37:35 +0100 Subject: [PATCH] feat: hostRules findAll function --- lib/util/host-rules.ts | 4 ++++ test/util/host-rules.spec.ts | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/util/host-rules.ts b/lib/util/host-rules.ts index 451f5f8f20..83080e3afc 100644 --- a/lib/util/host-rules.ts +++ b/lib/util/host-rules.ts @@ -164,6 +164,10 @@ export function hosts({ hostType }: { hostType: string }): string[] { .filter(Boolean); } +export function findAll({ hostType }: { hostType: string }): HostRule[] { + return hostRules.filter(rule => rule.hostType === hostType); +} + export function clear(): void { hostRules = []; sanitize.clear(); diff --git a/test/util/host-rules.spec.ts b/test/util/host-rules.spec.ts index 00bf21eceb..3e60d559d8 100644 --- a/test/util/host-rules.spec.ts +++ b/test/util/host-rules.spec.ts @@ -1,4 +1,4 @@ -import { add, find, clear, hosts } from '../../lib/util/host-rules'; +import { add, find, findAll, clear, hosts } from '../../lib/util/host-rules'; import { DATASOURCE_NUGET } from '../../lib/constants/data-binary-source'; import { PLATFORM_TYPE_AZURE } from '../../lib/constants/platforms'; @@ -148,4 +148,21 @@ describe('util/host-rules', () => { expect(res).toHaveLength(2); }); }); + describe('findAll()', () => { + it('warns and returns empty for bad search', () => { + expect(findAll({ abc: 'def' } as any)).toEqual([]); + }); + it('needs exact host matches', () => { + const hostRule = { + hostType: 'nuget', + hostName: 'nuget.org', + username: 'root', + password: 'p4$$w0rd', + token: undefined, + }; + add(hostRule); + expect(findAll({ hostType: 'nuget' })).toHaveLength(1); + expect(findAll({ hostType: 'nuget' })[0]).toEqual(hostRule); + }); + }); }); -- GitLab