Test for slashes in project repo as well

Signed-off-by: Andre Wanlin <awanlin@spotify.com>
This commit is contained in:
Andre Wanlin
2023-12-08 14:03:26 -06:00
parent 7c9af0bd28
commit 200c36ecf8
2 changed files with 26 additions and 2 deletions
@@ -334,7 +334,7 @@ describe('getAnnotationValuesFromEntity', () => {
});
});
describe('with more then expected slashes', () => {
describe('host-org with more then expected slashes', () => {
it('should throw incorrect format error', () => {
const entity: Entity = {
apiVersion: 'backstage.io/v1alpha1',
@@ -357,4 +357,28 @@ describe('getAnnotationValuesFromEntity', () => {
);
});
});
describe('project-repo with more then expected slashes', () => {
it('should throw incorrect format error', () => {
const entity: Entity = {
apiVersion: 'backstage.io/v1alpha1',
kind: 'Component',
metadata: {
namespace: 'default',
name: 'project-repo',
annotations: {
'dev.azure.com/project-repo': 'project/another/repo/final',
},
},
};
const test = () => {
return getAnnotationValuesFromEntity(entity);
};
expect(test).toThrow(
'Invalid value for annotation "dev.azure.com/project-repo"; expected format is: <project-name>/<repo-name>, found: "project/another/repo/final"',
);
});
});
});
@@ -68,7 +68,7 @@ function getProjectRepo(annotations?: Record<string, string>): {
return { project: undefined, repo: undefined };
}
if (annotation.includes('/')) {
if (annotation.split('/').length === 2) {
const [project, repo] = annotation.split('/');
if (project && repo) {
return { project, repo };