Skip to content

Commit

Permalink
fix: replace return with continue in for loop (#20)
Browse files Browse the repository at this point in the history
Refs: #19
  • Loading branch information
koyashiro authored Apr 22, 2024
1 parent 584589c commit 72a615c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
4 changes: 2 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
39 changes: 27 additions & 12 deletions src/lib.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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 "";
}
Expand Down Expand Up @@ -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 "";
}
Expand Down Expand Up @@ -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",
);
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ export function exportSecrets(core: ActionsCore) {
`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);
Expand Down

0 comments on commit 72a615c

Please sign in to comment.