adding test cases
Signed-off-by: Tarak Nath Tatwa <bikashcric1995@gmail.com>
This commit is contained in:
@@ -268,4 +268,163 @@ describe('AnnotateScmSlugEntityProcessor', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('azure', () => {
|
||||
it('adds annotation', async () => {
|
||||
const entity: Entity = {
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'Component',
|
||||
metadata: {
|
||||
name: 'my-component',
|
||||
},
|
||||
};
|
||||
const location: LocationSpec = {
|
||||
type: 'url',
|
||||
target:
|
||||
'https://dev.azure.com/organization/project/_git/repository?path=%2Fcatalog-info.yaml',
|
||||
};
|
||||
|
||||
const processor = AnnotateScmSlugEntityProcessor.fromConfig(
|
||||
new ConfigReader({}),
|
||||
);
|
||||
|
||||
expect(await processor.preProcessEntity(entity, location)).toEqual({
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'Component',
|
||||
metadata: {
|
||||
name: 'my-component',
|
||||
annotations: {
|
||||
'dev.azure.com/project-repo': 'project/repository',
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('does not override existing annotation', async () => {
|
||||
const entity: Entity = {
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'Component',
|
||||
metadata: {
|
||||
name: 'my-component',
|
||||
annotations: {
|
||||
'dev.azure.com/project-repo': 'myproj/myrepo',
|
||||
},
|
||||
},
|
||||
};
|
||||
const location: LocationSpec = {
|
||||
type: 'url',
|
||||
target:
|
||||
'https://dev.azure.com/organization/project/_git/repository?path=%2Fcatalog-info.yaml',
|
||||
};
|
||||
|
||||
const processor = AnnotateScmSlugEntityProcessor.fromConfig(
|
||||
new ConfigReader({}),
|
||||
);
|
||||
|
||||
expect(await processor.preProcessEntity(entity, location)).toEqual({
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'Component',
|
||||
metadata: {
|
||||
name: 'my-component',
|
||||
annotations: {
|
||||
'dev.azure.com/project-repo': 'myproj/myrepo',
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should not add annotation for other providers', async () => {
|
||||
const entity: Entity = {
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'Component',
|
||||
metadata: {
|
||||
name: 'my-component',
|
||||
},
|
||||
};
|
||||
const location: LocationSpec = {
|
||||
type: 'url',
|
||||
target:
|
||||
'https://not-in-mock-config.example.com/backstage/backstage/-/blob/master/catalog-info.yaml',
|
||||
};
|
||||
|
||||
const processor = AnnotateScmSlugEntityProcessor.fromConfig(
|
||||
new ConfigReader({}),
|
||||
);
|
||||
|
||||
expect(await processor.preProcessEntity(entity, location)).toEqual({
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'Component',
|
||||
metadata: {
|
||||
name: 'my-component',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should only process applicable kinds', async () => {
|
||||
const component: Entity = {
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'Component',
|
||||
metadata: {
|
||||
name: 'my-component',
|
||||
},
|
||||
};
|
||||
|
||||
const api: Entity = {
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'API',
|
||||
metadata: {
|
||||
name: 'my-component',
|
||||
},
|
||||
};
|
||||
|
||||
const system: Entity = {
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'System',
|
||||
metadata: {
|
||||
name: 'my-component',
|
||||
},
|
||||
};
|
||||
|
||||
const location: LocationSpec = {
|
||||
type: 'url',
|
||||
target:
|
||||
'https://dev.azure.com/organization/project/_git/repository?path=%2Fcatalog-info.yaml',
|
||||
};
|
||||
|
||||
const processor = AnnotateScmSlugEntityProcessor.fromConfig(
|
||||
new ConfigReader({}),
|
||||
{ kinds: ['API', 'Component'] },
|
||||
);
|
||||
|
||||
expect(await processor.preProcessEntity(component, location)).toEqual({
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'Component',
|
||||
metadata: {
|
||||
name: 'my-component',
|
||||
annotations: {
|
||||
'dev.azure.com/project-repo': 'project/repository',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(await processor.preProcessEntity(api, location)).toEqual({
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'API',
|
||||
metadata: {
|
||||
name: 'my-component',
|
||||
annotations: {
|
||||
'dev.azure.com/project-repo': 'project/repository',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(await processor.preProcessEntity(system, location)).toEqual({
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'System',
|
||||
metadata: {
|
||||
name: 'my-component',
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user