Skip to content

Commit 9b9e5e7

Browse files
committed
Test createStatusReportBase
1 parent b72eccb commit 9b9e5e7

File tree

6 files changed

+95
-8
lines changed

6 files changed

+95
-8
lines changed

lib/actions-util.js

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

lib/actions-util.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.

lib/actions-util.test.js

Lines changed: 35 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: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import test from "ava";
55
import * as sinon from "sinon";
66

77
import * as actionsutil from "./actions-util";
8+
import * as sharedEnv from "./shared-environment";
89
import { setupActionsVars, setupTests } from "./testing-utils";
910
import { initializeEnvironment, withTmpDir } from "./util";
1011

@@ -275,3 +276,54 @@ test("workflowEventName()", async (t) => {
275276
process.env["CODESCANNING_EVENT_NAME"] = "push";
276277
t.deepEqual(actionsutil.workflowEventName(), "push");
277278
});
279+
280+
test("createStatusReportBase", async (t) => {
281+
await withTmpDir(async (tmpDir: string) => {
282+
setupActionsVars(tmpDir, tmpDir);
283+
284+
process.env["GITHUB_REF"] = "refs/heads/main";
285+
process.env["GITHUB_SHA"] = "a".repeat(40);
286+
process.env["GITHUB_RUN_ID"] = "100";
287+
process.env["GITHUB_RUN_ATTEMPT"] = "2";
288+
process.env["GITHUB_REPOSITORY"] = "octocat/HelloWorld";
289+
process.env["CODEQL_ACTION_ANALYSIS_KEY"] = "analysis-key";
290+
process.env["RUNNER_OS"] = "macOS";
291+
292+
const getRequiredInput = sinon.stub(actionsutil, "getRequiredInput");
293+
getRequiredInput.withArgs("matrix").resolves("input/matrix");
294+
295+
const statusReport = await actionsutil.createStatusReportBase(
296+
"init",
297+
"failure",
298+
new Date("May 19, 2023 05:19:00"),
299+
"failure cause",
300+
"exception stack trace"
301+
);
302+
303+
t.assert(typeof statusReport.job_run_uuid === "string");
304+
t.assert(statusReport.workflow_run_id === 100);
305+
t.assert(statusReport.workflow_run_attempt === 2);
306+
t.assert(
307+
statusReport.workflow_name === (process.env["GITHUB_WORKFLOW"] || "")
308+
);
309+
t.assert(statusReport.job_name === (process.env["GITHUB_JOB"] || ""));
310+
t.assert(statusReport.analysis_key === "analysis-key");
311+
t.assert(statusReport.commit_oid === process.env["GITHUB_SHA"]);
312+
t.assert(statusReport.ref === process.env["GITHUB_REF"]);
313+
t.assert(statusReport.action_name === "init");
314+
t.assert(statusReport.action_oid === "unknown");
315+
t.assert(
316+
statusReport.started_at ===
317+
process.env[sharedEnv.CODEQL_WORKFLOW_STARTED_AT]
318+
);
319+
t.assert(
320+
statusReport.action_started_at ===
321+
new Date("May 19, 2023 05:19:00").toISOString()
322+
);
323+
t.assert(statusReport.status === "failure");
324+
t.assert(statusReport.cause === "failure cause");
325+
t.assert(statusReport.exception === "exception stack trace");
326+
t.assert(statusReport.runner_os === process.env["RUNNER_OS"]);
327+
t.assert(typeof statusReport.action_version === "string");
328+
});
329+
});

src/actions-util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ const pkg = require("../package.json") as JSONSchemaForNPMPackageJsonFiles;
3636
*
3737
* This allows us to get stronger type checking of required/optional inputs.
3838
*/
39-
export function getRequiredInput(name: string): string {
39+
export const getRequiredInput = function (name: string): string {
4040
return core.getInput(name, { required: true });
41-
}
41+
};
4242

4343
/**
4444
* Wrapper around core.getInput that converts empty inputs to undefined.

0 commit comments

Comments
 (0)