From 72a615c0a59fd1302e92c4117fa5474b3df6a3ae Mon Sep 17 00:00:00 2001 From: koyashiro <6698252+koyashiro@users.noreply.github.com> Date: Tue, 23 Apr 2024 00:50:23 +0900 Subject: [PATCH] fix: replace `return` with `continue` in for loop (#20) Refs: #19 --- dist/index.js | 4 ++-- src/lib.test.ts | 39 +++++++++++++++++++++++++++------------ src/lib.ts | 4 ++-- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/dist/index.js b/dist/index.js index 58e64ad..1296ee7 100644 --- a/dist/index.js +++ b/dist/index.js @@ -31070,11 +31070,11 @@ function exportSecrets(core) { for (const [key, value] of Object.entries(secrets)) { if (downcaseTfVar && key.startsWith("TF_VAR_")) { core.exportVariable(`TF_VAR_${key.replace(/^TF_VAR_/, "").toLowerCase()}`, value); - return; + continue; } if (downcaseTfToken && key.startsWith("TF_TOKEN_")) { core.exportVariable(`TF_TOKEN_${key.replace(/^TF_TOKEN_/, "").toLowerCase()}`, value); - return; + continue; } core.exportVariable(key, value); } diff --git a/src/lib.test.ts b/src/lib.test.ts index 65129d2..db8e3f4 100644 --- a/src/lib.test.ts +++ b/src/lib.test.ts @@ -8,7 +8,7 @@ describe("exportSecrets()", () => { getInput: vi.fn().mockImplementation((s: string) => { switch (s) { case "secrets": - return '{"KEY_A":"VALUE_A","KEY_B":"VALUE_B","KEY_C":"VALUE_C","TF_VAR_KEY_D":"VALUE_D"}'; + return '{"KEY_A":"VALUE_A","KEY_B":"VALUE_B","KEY_C":"VALUE_C","TF_VAR_KEY_D":"VALUE_D","TF_TOKEN_KEY_E":"VALUE_E"}'; case "downcase-tf-var": return ""; case "downcase-tf-token": @@ -59,19 +59,24 @@ describe("exportSecrets()", () => { "TF_VAR_KEY_D", "VALUE_D", ); + expect(coreMock.exportVariable).toHaveBeenNthCalledWith( + 5, + "TF_TOKEN_KEY_E", + "VALUE_E", + ); }); }); - describe("success_downcase-tf-token", () => { + describe("success_downcase-tf-var", () => { const coreMock = { getInput: vi.fn().mockImplementation((s: string) => { switch (s) { case "secrets": - return '{"KEY_A":"VALUE_A","KEY_B":"VALUE_B","KEY_C":"VALUE_C","TF_TOKEN_EXAMPLE_COM":"xyz"}'; + return '{"KEY_A":"VALUE_A","KEY_B":"VALUE_B","KEY_C":"VALUE_C","TF_VAR_KEY_D":"VALUE_D","TF_TOKEN_KEY_E":"VALUE_E"}'; case "downcase-tf-var": - return ""; - case "downcase-tf-token": return "true"; + case "downcase-tf-token": + return ""; default: return ""; } @@ -115,22 +120,27 @@ describe("exportSecrets()", () => { ); expect(coreMock.exportVariable).toHaveBeenNthCalledWith( 4, - "TF_TOKEN_example_com", - "xyz", + "TF_VAR_key_d", + "VALUE_D", + ); + expect(coreMock.exportVariable).toHaveBeenNthCalledWith( + 5, + "TF_TOKEN_KEY_E", + "VALUE_E", ); }); }); - describe("success_downcase-tf-var", () => { + describe("success_downcase-tf-token", () => { const coreMock = { getInput: vi.fn().mockImplementation((s: string) => { switch (s) { case "secrets": - return '{"KEY_A":"VALUE_A","KEY_B":"VALUE_B","KEY_C":"VALUE_C","TF_VAR_KEY_D":"VALUE_D"}'; + return '{"KEY_A":"VALUE_A","KEY_B":"VALUE_B","KEY_C":"VALUE_C","TF_VAR_KEY_D":"VALUE_D","TF_TOKEN_KEY_E":"VALUE_E"}'; case "downcase-tf-var": - return "true"; - case "downcase-tf-token": return ""; + case "downcase-tf-token": + return "true"; default: return ""; } @@ -174,9 +184,14 @@ describe("exportSecrets()", () => { ); expect(coreMock.exportVariable).toHaveBeenNthCalledWith( 4, - "TF_VAR_key_d", + "TF_VAR_KEY_D", "VALUE_D", ); + expect(coreMock.exportVariable).toHaveBeenNthCalledWith( + 5, + "TF_TOKEN_key_e", + "VALUE_E", + ); }); }); diff --git a/src/lib.ts b/src/lib.ts index 74462ca..dd611c9 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -22,7 +22,7 @@ export function exportSecrets(core: ActionsCore) { `TF_VAR_${key.replace(/^TF_VAR_/, "").toLowerCase()}`, value, ); - return; + continue; } if (downcaseTfToken && key.startsWith("TF_TOKEN_")) { @@ -30,7 +30,7 @@ export function exportSecrets(core: ActionsCore) { `TF_TOKEN_${key.replace(/^TF_TOKEN_/, "").toLowerCase()}`, value, ); - return; + continue; } core.exportVariable(key, value);