Test for slashes in project repo as well
Signed-off-by: Andre Wanlin <awanlin@spotify.com>
This commit is contained in:
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user