From 9d6c429801c2ae1bddad6ae1694b9a2caff01f9e Mon Sep 17 00:00:00 2001 From: Kiss Miklos Date: Mon, 6 Mar 2023 18:45:30 +0100 Subject: [PATCH] add glob and wildcard tests Signed-off-by: Kiss Miklos --- .../codeowners/CodeOwnersProcessor.test.ts | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/plugins/catalog-backend/src/modules/codeowners/CodeOwnersProcessor.test.ts b/plugins/catalog-backend/src/modules/codeowners/CodeOwnersProcessor.test.ts index 8e1fbca726..6c2774a6fb 100644 --- a/plugins/catalog-backend/src/modules/codeowners/CodeOwnersProcessor.test.ts +++ b/plugins/catalog-backend/src/modules/codeowners/CodeOwnersProcessor.test.ts @@ -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' }, + }); + }); }); });