From f6f75515f15527fd9c5bb90559a2fc67adb3072a Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Mon, 26 Sep 2022 10:32:09 +0200 Subject: [PATCH] catalog-backend: integration test, add provider replacement test Signed-off-by: Patrik Oldsberg --- .../catalog-backend/src/integration.test.ts | 51 ++++++++++++++++++- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/plugins/catalog-backend/src/integration.test.ts b/plugins/catalog-backend/src/integration.test.ts index 745678fc70..e61a7d7038 100644 --- a/plugins/catalog-backend/src/integration.test.ts +++ b/plugins/catalog-backend/src/integration.test.ts @@ -317,10 +317,13 @@ class TestHarness { return errors; } - async setInputEntities(entities: Entity[]) { + async setInputEntities(entities: (Entity & { locationKey?: string })[]) { return this.#provider.getConnection().applyMutation({ type: 'full', - entities: entities.map(entity => ({ entity })), + entities: entities.map(({ locationKey, ...entity }) => ({ + entity, + locationKey, + })), }); } @@ -493,4 +496,48 @@ describe('Catalog Backend Integration', () => { }), }); }); + + it('should not replace matching provided entities', async () => { + const harness = await TestHarness.create(); + + const entityA = { + apiVersion: 'backstage.io/v1alpha1', + kind: 'Component', + metadata: { + name: 'a', + annotations: { + 'backstage.io/managed-by-location': 'url:.', + 'backstage.io/managed-by-origin-location': 'url:.', + }, + }, + }; + const entityB = { + apiVersion: 'backstage.io/v1alpha1', + kind: 'Component', + metadata: { + name: 'b', + annotations: { + 'backstage.io/managed-by-location': 'url:.', + 'backstage.io/managed-by-origin-location': 'url:.', + }, + }, + }; + + const entities = [entityA, { locationKey: 'loc', ...entityB }]; + + await harness.setInputEntities(entities); + await expect(harness.process()).resolves.toEqual({}); + + const outputEntities = await harness.getOutputEntities(); + + await expect(harness.getOutputEntities()).resolves.toEqual({ + 'component:default/a': expect.anything(), + 'component:default/b': expect.anything(), + }); + + await harness.setInputEntities(entities); + await expect(harness.process()).resolves.toEqual({}); + + await expect(harness.getOutputEntities()).resolves.toEqual(outputEntities); + }); });