Skip to content
Snippets Groups Projects
Commit d93036b8 authored by Ricky Patel's avatar Ricky Patel Committed by Rhys Arkins
Browse files

feat: hostRules findAll function

parent 8b9bfbe4
Branches
No related tags found
No related merge requests found
...@@ -164,6 +164,10 @@ export function hosts({ hostType }: { hostType: string }): string[] { ...@@ -164,6 +164,10 @@ export function hosts({ hostType }: { hostType: string }): string[] {
.filter(Boolean); .filter(Boolean);
} }
export function findAll({ hostType }: { hostType: string }): HostRule[] {
return hostRules.filter(rule => rule.hostType === hostType);
}
export function clear(): void { export function clear(): void {
hostRules = []; hostRules = [];
sanitize.clear(); sanitize.clear();
......
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 { DATASOURCE_NUGET } from '../../lib/constants/data-binary-source';
import { PLATFORM_TYPE_AZURE } from '../../lib/constants/platforms'; import { PLATFORM_TYPE_AZURE } from '../../lib/constants/platforms';
...@@ -148,4 +148,21 @@ describe('util/host-rules', () => { ...@@ -148,4 +148,21 @@ describe('util/host-rules', () => {
expect(res).toHaveLength(2); 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);
});
});
}); });
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment