Add unit tests for entity processor and validator

Signed-off-by: vahagsaribekyan <32436397+vahagsaribekyan@users.noreply.github.com>
This commit is contained in:
vahagsaribekyan
2024-09-11 13:19:10 +04:00
committed by GitHub
parent 03a05536c0
commit cada3c3c09
@@ -46,13 +46,14 @@ describe('BuiltinKindsEntityProcessor', () => {
providesApis: ['b'],
consumesApis: ['c'],
dependsOn: ['Resource:r', 'Component:d'],
dependencyOf: ['Resource:f', 'Component:g'],
system: 's',
},
};
await processor.postProcessEntity(entity, location, emit);
expect(emit).toHaveBeenCalledTimes(14);
expect(emit).toHaveBeenCalledTimes(18);
expect(emit).toHaveBeenCalledWith({
type: 'relation',
relation: {
@@ -132,6 +133,38 @@ describe('BuiltinKindsEntityProcessor', () => {
type: 'dependencyOf',
target: { kind: 'Component', namespace: 'default', name: 'n' },
},
});
expect(emit).toHaveBeenCalledWith({
type: 'relation',
relation: {
source: { kind: 'Component', namespace: 'default', name: 'n' },
type: 'dependencyOf',
target: { kind: 'Resource', namespace: 'default', name: 'f' },
},
});
expect(emit).toHaveBeenCalledWith({
type: 'relation',
relation: {
source: { kind: 'Resource', namespace: 'default', name: 'f' },
type: 'dependsOn',
target: { kind: 'Component', namespace: 'default', name: 'n' },
},
});
expect(emit).toHaveBeenCalledWith({
type: 'relation',
relation: {
source: { kind: 'Component', namespace: 'default', name: 'n' },
type: 'dependencyOf',
target: { kind: 'Component', namespace: 'default', name: 'g' },
},
});
expect(emit).toHaveBeenCalledWith({
type: 'relation',
relation: {
source: { kind: 'Component', namespace: 'default', name: 'g' },
type: 'dependsOn',
target: { kind: 'Component', namespace: 'default', name: 'n' },
},
});
expect(emit).toHaveBeenCalledWith({
type: 'relation',
@@ -190,6 +223,29 @@ describe('BuiltinKindsEntityProcessor', () => {
);
});
it('generates an error for component entities with unspecified dependencyOf entity reference kinds', async () => {
const entity: ComponentEntity = {
apiVersion: 'backstage.io/v1alpha1',
kind: 'Component',
metadata: { name: 'n' },
spec: {
type: 'service',
owner: 'o',
subcomponentOf: 's',
lifecycle: 'l',
providesApis: ['b'],
consumesApis: ['c'],
dependencyOf: ['y'],
system: 's',
},
};
await expect(
processor.postProcessEntity(entity, location, emit),
).rejects.toThrow(
'Entity reference "y" had missing or empty kind (e.g. did not start with "component:" or similar)',
);
});
it('generates relations for api entities', async () => {
const entity: ApiEntity = {
apiVersion: 'backstage.io/v1alpha1',