add glob and wildcard tests

Signed-off-by: Kiss Miklos <miklos@roadie.io>
This commit is contained in:
Kiss Miklos
2023-03-06 18:45:30 +01:00
parent c85b736016
commit 9d6c429801
@@ -17,11 +17,13 @@
import { getVoidLogger } from '@backstage/backend-common';
import { ConfigReader } from '@backstage/config';
import { CodeOwnersProcessor } from './CodeOwnersProcessor';
import { LocationSpec } from '@backstage/plugin-catalog-node';
import { LocationSpec } from '@backstage/plugin-catalog-common';
const mockCodeOwnersText = () => `
* @acme/team-foo @acme/team-bar
/docs @acme/team-docs
* @acme/team-foo @acme/team-bar
/docs @acme/team-docs
/plugins/catalog-* @backstage/maintainers @backstage/catalog-core
**/logs @logs-owner
`;
describe('CodeOwnersProcessor', () => {
@@ -105,7 +107,7 @@ describe('CodeOwnersProcessor', () => {
spec: { owner: 'team-foo' },
});
});
it('should use the "backstage.io/managed-by-location" annotation as pattern', async () => {
it('should match owner based on the targetUrl', async () => {
const { entity, processor } = setupTest();
const result = await processor.preProcessEntity(
@@ -118,5 +120,31 @@ describe('CodeOwnersProcessor', () => {
spec: { owner: 'team-docs' },
});
});
it('should match wildcard pattern', async () => {
const { entity, processor } = setupTest();
const result = await processor.preProcessEntity(
entity as any,
mockLocation({ basePath: 'plugins/catalog-foo' }),
);
expect(result).toEqual({
...entity,
spec: { owner: 'maintainers' },
});
});
it('should match glob pattern', async () => {
const { entity, processor } = setupTest();
const result = await processor.preProcessEntity(
entity as any,
mockLocation({ basePath: 'plugins/catalog-foo/logs/1.txt' }),
);
expect(result).toEqual({
...entity,
spec: { owner: 'User:logs-owner' },
});
});
});
});