Skip to content

Commit

Permalink
Test createStatusReportBase
Browse files Browse the repository at this point in the history
  • Loading branch information
angelapwen committed May 22, 2023
1 parent b72eccb commit 9b9e5e7
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 8 deletions.
8 changes: 4 additions & 4 deletions lib/actions-util.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.js.map

Large diffs are not rendered by default.

35 changes: 35 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

Large diffs are not rendered by default.

52 changes: 52 additions & 0 deletions src/actions-util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import test from "ava";
import * as sinon from "sinon";

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

Expand Down Expand Up @@ -275,3 +276,54 @@ test("workflowEventName()", async (t) => {
process.env["CODESCANNING_EVENT_NAME"] = "push";
t.deepEqual(actionsutil.workflowEventName(), "push");
});

test("createStatusReportBase", async (t) => {
await withTmpDir(async (tmpDir: string) => {
setupActionsVars(tmpDir, tmpDir);

process.env["GITHUB_REF"] = "refs/heads/main";
process.env["GITHUB_SHA"] = "a".repeat(40);
process.env["GITHUB_RUN_ID"] = "100";
process.env["GITHUB_RUN_ATTEMPT"] = "2";
process.env["GITHUB_REPOSITORY"] = "octocat/HelloWorld";
process.env["CODEQL_ACTION_ANALYSIS_KEY"] = "analysis-key";
process.env["RUNNER_OS"] = "macOS";

const getRequiredInput = sinon.stub(actionsutil, "getRequiredInput");
getRequiredInput.withArgs("matrix").resolves("input/matrix");

const statusReport = await actionsutil.createStatusReportBase(
"init",
"failure",
new Date("May 19, 2023 05:19:00"),
"failure cause",
"exception stack trace"
);

t.assert(typeof statusReport.job_run_uuid === "string");
t.assert(statusReport.workflow_run_id === 100);
t.assert(statusReport.workflow_run_attempt === 2);
t.assert(
statusReport.workflow_name === (process.env["GITHUB_WORKFLOW"] || "")
);
t.assert(statusReport.job_name === (process.env["GITHUB_JOB"] || ""));
t.assert(statusReport.analysis_key === "analysis-key");
t.assert(statusReport.commit_oid === process.env["GITHUB_SHA"]);
t.assert(statusReport.ref === process.env["GITHUB_REF"]);
t.assert(statusReport.action_name === "init");
t.assert(statusReport.action_oid === "unknown");
t.assert(
statusReport.started_at ===
process.env[sharedEnv.CODEQL_WORKFLOW_STARTED_AT]
);
t.assert(
statusReport.action_started_at ===
new Date("May 19, 2023 05:19:00").toISOString()
);
t.assert(statusReport.status === "failure");
t.assert(statusReport.cause === "failure cause");
t.assert(statusReport.exception === "exception stack trace");
t.assert(statusReport.runner_os === process.env["RUNNER_OS"]);
t.assert(typeof statusReport.action_version === "string");
});
});
4 changes: 2 additions & 2 deletions src/actions-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ const pkg = require("../package.json") as JSONSchemaForNPMPackageJsonFiles;
*
* This allows us to get stronger type checking of required/optional inputs.
*/
export function getRequiredInput(name: string): string {
export const getRequiredInput = function (name: string): string {
return core.getInput(name, { required: true });
}
};

/**
* Wrapper around core.getInput that converts empty inputs to undefined.
Expand Down

0 comments on commit 9b9e5e7

Please sign in to comment.