Emit relations for subcomponents

This commit is contained in:
James Turley
2021-01-12 14:48:23 +00:00
parent eeb6f3ba93
commit 868f813992
3 changed files with 33 additions and 1 deletions
@@ -38,6 +38,7 @@ describe('BuiltinKindsEntityProcessor', () => {
spec: {
type: 'service',
owner: 'o',
subcomponentOf: 's',
lifecycle: 'l',
providesApis: ['b'],
consumesApis: ['c'],
@@ -46,7 +47,7 @@ describe('BuiltinKindsEntityProcessor', () => {
await processor.postProcessEntity(entity, location, emit);
expect(emit).toBeCalledTimes(6);
expect(emit).toBeCalledTimes(8);
expect(emit).toBeCalledWith({
type: 'relation',
relation: {
@@ -95,6 +96,22 @@ describe('BuiltinKindsEntityProcessor', () => {
target: { kind: 'API', namespace: 'default', name: 'c' },
},
});
expect(emit).toBeCalledWith({
type: 'relation',
relation: {
source: { kind: 'Component', namespace: 'default', name: 's' },
type: 'hasPart',
target: { kind: 'Component', namespace: 'default', name: 'n' },
},
});
expect(emit).toBeCalledWith({
type: 'relation',
relation: {
source: { kind: 'Component', namespace: 'default', name: 'n' },
type: 'partOf',
target: { kind: 'Component', namespace: 'default', name: 's' },
},
});
});
it('generates relations for api entities', async () => {
@@ -32,6 +32,8 @@ import {
RELATION_CONSUMES_API,
RELATION_HAS_MEMBER,
RELATION_MEMBER_OF,
RELATION_HAS_PART,
RELATION_PART_OF,
RELATION_OWNED_BY,
RELATION_OWNER_OF,
RELATION_PARENT_OF,
@@ -115,6 +117,12 @@ export class BuiltinKindsEntityProcessor implements CatalogProcessor {
RELATION_OWNED_BY,
RELATION_OWNER_OF,
);
doEmit(
component.spec.subcomponentOf,
{ defaultKind: 'Component', defaultNamespace: selfRef.namespace },
RELATION_PART_OF,
RELATION_HAS_PART,
);
doEmit(
component.spec.providesApis,
{ defaultKind: 'API', defaultNamespace: selfRef.namespace },