diff --git a/lib/util/host-rules.ts b/lib/util/host-rules.ts index 451f5f8f2029b6c748343407944537924f2d19ad..83080e3afc8f03bcf640a7d148b88c76f5afbf16 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 00bf21ecebc05ec2746bfb7a3d102eb1e698cc9a..3e60d559d8cd05d78516f356a9fc0b8459c8144a 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); + }); + }); });