Skip to content

Commit d58039a

Browse files
authored
Merge pull request #1435 from github/orhantoy/add-CODE_SCANNING_REF-tests
Add tests for CODE_SCANNING_REF
2 parents 37a4496 + b7028af commit d58039a

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

lib/actions-util.test.js

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/actions-util.test.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/actions-util.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,34 @@ test("getRef() returns ref provided as an input and ignores current HEAD", async
8888
});
8989
});
9090

91+
test("getRef() returns CODE_SCANNING_REF as a fallback for GITHUB_REF", async (t) => {
92+
await withTmpDir(async (tmpDir: string) => {
93+
setupActionsVars(tmpDir, tmpDir);
94+
const expectedRef = "refs/pull/1/HEAD";
95+
const currentSha = "a".repeat(40);
96+
process.env["CODE_SCANNING_REF"] = expectedRef;
97+
process.env["GITHUB_REF"] = "";
98+
process.env["GITHUB_SHA"] = currentSha;
99+
100+
const actualRef = await actionsutil.getRef();
101+
t.deepEqual(actualRef, expectedRef);
102+
});
103+
});
104+
105+
test("getRef() returns GITHUB_REF over CODE_SCANNING_REF if both are provided", async (t) => {
106+
await withTmpDir(async (tmpDir: string) => {
107+
setupActionsVars(tmpDir, tmpDir);
108+
const expectedRef = "refs/pull/1/merge";
109+
const currentSha = "a".repeat(40);
110+
process.env["CODE_SCANNING_REF"] = "refs/pull/1/HEAD";
111+
process.env["GITHUB_REF"] = expectedRef;
112+
process.env["GITHUB_SHA"] = currentSha;
113+
114+
const actualRef = await actionsutil.getRef();
115+
t.deepEqual(actualRef, expectedRef);
116+
});
117+
});
118+
91119
test("getRef() throws an error if only `ref` is provided as an input", async (t) => {
92120
await withTmpDir(async (tmpDir: string) => {
93121
setupActionsVars(tmpDir, tmpDir);

0 commit comments

Comments
 (0)