Skip to content

Commit

Permalink
Merge pull request #1435 from github/orhantoy/add-CODE_SCANNING_REF-t…
Browse files Browse the repository at this point in the history
…ests

Add tests for CODE_SCANNING_REF
  • Loading branch information
orhantoy committed Dec 13, 2022
2 parents 37a4496 + b7028af commit d58039a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
24 changes: 24 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.

28 changes: 28 additions & 0 deletions src/actions-util.test.ts
Expand Up @@ -88,6 +88,34 @@ 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_REF"] = "";
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 d58039a

Please sign in to comment.