0
0
mirror of https://github.com/renovatebot/renovate.git synced 2024-12-22 13:38:32 +00:00
renovatebot_renovate/lib/util/package-rules/repositories.spec.ts
Rhys Arkins 879f7cc212 feat(packageRules): migrate matchers and excludes (#28602)
Co-authored-by: Sebastian Poxhofer <secustor@users.noreply.github.com>
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
2024-07-25 15:28:16 +02:00

190 lines
4.7 KiB
TypeScript

import { RepositoriesMatcher } from './repositories';
describe('util/package-rules/repositories', () => {
const repositoryMatcher = new RepositoriesMatcher();
describe('match', () => {
it('should return null if match repositories is not defined', () => {
const result = repositoryMatcher.matches(
{
repository: 'org/repo',
},
{
matchRepositories: undefined,
},
);
expect(result).toBeNull();
});
it('should return false if repository is not defined', () => {
const result = repositoryMatcher.matches(
{
repository: undefined,
},
{
matchRepositories: ['org/repo'],
},
);
expect(result).toBeFalse();
});
it('should return true if repository matches regex pattern', () => {
const result = repositoryMatcher.matches(
{
repository: 'org/repo',
},
{
matchRepositories: ['/^org/repo$/'],
},
);
expect(result).toBeTrue();
});
it('should return false if repository has invalid regex pattern', () => {
const result = repositoryMatcher.matches(
{
repository: 'org/repo',
},
{
matchRepositories: ['/[/'],
},
);
expect(result).toBeFalse();
});
it('should return false if repository does not match regex pattern', () => {
const result = repositoryMatcher.matches(
{
repository: 'org/repo',
},
{
matchRepositories: ['/^org/other-repo$/'],
},
);
expect(result).toBeFalse();
});
it('should return true if repository matches minimatch pattern', () => {
const result = repositoryMatcher.matches(
{
repository: 'org/repo',
},
{
matchRepositories: ['org/**'],
},
);
expect(result).toBeTrue();
});
it('should return false if repository does not match minimatch pattern', () => {
const result = repositoryMatcher.matches(
{
repository: 'org/repo',
},
{
matchRepositories: ['other-org/**'],
},
);
expect(result).toBeFalse();
});
it('should return true if repository matches at least one pattern', () => {
const result = repositoryMatcher.matches(
{
repository: 'org/repo-archived',
},
{
matchRepositories: ['/^org/repo$/', '**/*-archived'],
},
);
expect(result).toBeTrue();
});
});
describe('excludes', () => {
it('should return false if exclude repository is not defined', () => {
const result = repositoryMatcher.matches(
{
repository: undefined,
},
{
matchRepositories: ['!org/repo'],
},
);
expect(result).toBeFalse();
});
it('should return false if exclude repository matches regex pattern', () => {
const result = repositoryMatcher.matches(
{
repository: 'org/repo',
},
{
matchRepositories: ['!/^org/repo$/'],
},
);
expect(result).toBeFalse();
});
it('should return true if exclude repository has invalid regex pattern', () => {
const result = repositoryMatcher.matches(
{
repository: 'org/repo',
},
{
matchRepositories: ['!/[/'],
},
);
expect(result).toBeTrue();
});
it('should return true if exclude repository does not match regex pattern', () => {
const result = repositoryMatcher.matches(
{
repository: 'org/repo',
},
{
matchRepositories: ['!/^org/other-repo$/'],
},
);
expect(result).toBeTrue();
});
it('should return false if exclude repository matches minimatch pattern', () => {
const result = repositoryMatcher.matches(
{
repository: 'org/repo',
},
{
matchRepositories: ['!org/**'],
},
);
expect(result).toBeFalse();
});
it('should return true if exclude repository does not match minimatch pattern', () => {
const result = repositoryMatcher.matches(
{
repository: 'org/repo',
},
{
matchRepositories: ['!other-org/**'],
},
);
expect(result).toBeTrue();
});
it('should return false if exclude repository matches at least one pattern', () => {
const result = repositoryMatcher.matches(
{
repository: 'org/repo-archived',
},
{
matchRepositories: ['!/^org/repo$/', '!**/*-archived'],
},
);
expect(result).toBeFalse();
});
});
});