Using stringEntityRef for comparision

Signed-off-by: Nicolas Arnold <nic@roadie.io>
This commit is contained in:
Nicolas Arnold
2021-11-24 09:31:12 +00:00
parent f9c0ad85d9
commit f658a34178
2 changed files with 10 additions and 4 deletions
@@ -196,7 +196,7 @@ describe('DefaultLocationServiceTest', () => {
{ type: 'url', target: 'https://backstage.io/catalog-info.yaml' },
true,
),
).rejects.toThrowError('Duplicate nested entity: foo');
).rejects.toThrowError('Duplicate nested entity: location:default/foo');
});
it('should return exists false when the location does not exist beforehand', async () => {
@@ -19,6 +19,7 @@ import {
LocationSpec,
LOCATION_ANNOTATION,
ORIGIN_LOCATION_ANNOTATION,
stringifyEntityRef,
} from '@backstage/catalog-model';
import {
CatalogProcessingOrchestrator,
@@ -69,13 +70,18 @@ export class DefaultLocationService implements LocationService {
});
if (processed.ok) {
const { metadata, kind } = processed.completedEntity;
if (
entities.some(
e => e.metadata.name === metadata.name && e.kind === kind,
e =>
stringifyEntityRef(e) ===
stringifyEntityRef(processed.completedEntity),
)
) {
throw new Error(`Duplicate nested entity: ${metadata.name}`);
throw new Error(
`Duplicate nested entity: ${stringifyEntityRef(
processed.completedEntity,
)}`,
);
}
unprocessedEntities.push(...processed.deferredEntities);
entities.push(processed.completedEntity);