Skip to content

Commit

Permalink
Add tests for CODE_SCANNING_REF
Browse files Browse the repository at this point in the history
  • Loading branch information
orhantoy committed Dec 13, 2022
1 parent 899bf9c commit ccee4c6
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
23 changes: 23 additions & 0 deletions lib/actions-util.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/actions-util.test.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions src/actions-util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,33 @@ test("getRef() returns ref provided as an input and ignores current HEAD", async
});
});

test("getRef() returns CODE_SCANNING_REF as a fallback for GITHUB_REF", async (t) => {
await withTmpDir(async (tmpDir: string) => {
setupActionsVars(tmpDir, tmpDir);
const expectedRef = "refs/pull/1/HEAD";
const currentSha = "a".repeat(40);
process.env["CODE_SCANNING_REF"] = expectedRef;
process.env["GITHUB_SHA"] = currentSha;

const actualRef = await actionsutil.getRef();
t.deepEqual(actualRef, expectedRef);
});
});

test("getRef() returns GITHUB_REF over CODE_SCANNING_REF if both are provided", async (t) => {
await withTmpDir(async (tmpDir: string) => {
setupActionsVars(tmpDir, tmpDir);
const expectedRef = "refs/pull/1/merge";
const currentSha = "a".repeat(40);
process.env["CODE_SCANNING_REF"] = "refs/pull/1/HEAD";
process.env["GITHUB_REF"] = expectedRef;
process.env["GITHUB_SHA"] = currentSha;

const actualRef = await actionsutil.getRef();
t.deepEqual(actualRef, expectedRef);
});
});

test("getRef() throws an error if only `ref` is provided as an input", async (t) => {
await withTmpDir(async (tmpDir: string) => {
setupActionsVars(tmpDir, tmpDir);
Expand Down

0 comments on commit ccee4c6

Please sign in to comment.