From 5696c46d0b87ccb3fb88075f2057bb6b6d11cd46 Mon Sep 17 00:00:00 2001 From: Matt Benson Date: Mon, 23 Oct 2023 20:25:45 -0500 Subject: [PATCH] test that one invalid iteration blocks the entire iterated action and identifies the offending key Signed-off-by: Matt Benson --- .../tasks/NunjucksWorkflowRunner.test.ts | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/plugins/scaffolder-backend/src/scaffolder/tasks/NunjucksWorkflowRunner.test.ts b/plugins/scaffolder-backend/src/scaffolder/tasks/NunjucksWorkflowRunner.test.ts index 30856482a1..076c9e1a11 100644 --- a/plugins/scaffolder-backend/src/scaffolder/tasks/NunjucksWorkflowRunner.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/tasks/NunjucksWorkflowRunner.test.ts @@ -674,6 +674,34 @@ describe('DefaultWorkflowRunner', () => { ); } }); + + it('should validate each action iteration', async () => { + const task = createMockTaskWithSpec({ + apiVersion: 'scaffolder.backstage.io/v1beta3', + steps: [ + { + id: 'test', + name: 'name', + each: '${{parameters.data}}', + action: 'jest-validated-action', + input: { foo: '${{each.value.foo}}' }, + }, + ], + output: {}, + parameters: { + data: [ + { + foo: 0, + }, + {}, + ], + }, + }); + await expect(runner.execute(task)).rejects.toThrow( + 'Invalid input passed to action jest-validated-action[1], instance requires property "foo"', + ); + expect(fakeActionHandler).not.toHaveBeenCalled(); + }); }); describe('secrets', () => {