Add unit test for YAML support in CODEQL_ACTION_EXTRA_OPTIONS
This commit is contained in:
parent
2a3ca27b96
commit
4e764dc701
3 changed files with 25 additions and 5 deletions
12
lib/util.test.js
generated
12
lib/util.test.js
generated
|
|
@ -31,6 +31,7 @@ const os = __importStar(require("os"));
|
|||
const path_1 = __importDefault(require("path"));
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const ava_1 = __importDefault(require("ava"));
|
||||
const yaml = __importStar(require("js-yaml"));
|
||||
const sinon = __importStar(require("sinon"));
|
||||
const api = __importStar(require("./api-client"));
|
||||
const environment_1 = require("./environment");
|
||||
|
|
@ -136,16 +137,23 @@ for (const { input, totalMemoryMb, platform, expectedMemoryValue, reservedPercen
|
|||
t.deepEqual(util.getExtraOptionsEnvParam(), options);
|
||||
process.env.CODEQL_ACTION_EXTRA_OPTIONS = origExtraOptions;
|
||||
});
|
||||
(0, ava_1.default)("getExtraOptionsEnvParam() succeeds on valid options", (t) => {
|
||||
(0, ava_1.default)("getExtraOptionsEnvParam() succeeds on valid JSON options", (t) => {
|
||||
const origExtraOptions = process.env.CODEQL_ACTION_EXTRA_OPTIONS;
|
||||
const options = { database: { init: ["--debug"] } };
|
||||
process.env.CODEQL_ACTION_EXTRA_OPTIONS = JSON.stringify(options);
|
||||
t.deepEqual(util.getExtraOptionsEnvParam(), options);
|
||||
process.env.CODEQL_ACTION_EXTRA_OPTIONS = origExtraOptions;
|
||||
});
|
||||
(0, ava_1.default)("getExtraOptionsEnvParam() succeeds on valid YAML options", (t) => {
|
||||
const origExtraOptions = process.env.CODEQL_ACTION_EXTRA_OPTIONS;
|
||||
const options = { database: { init: ["--debug"] } };
|
||||
process.env.CODEQL_ACTION_EXTRA_OPTIONS = yaml.dump(options);
|
||||
t.deepEqual(util.getExtraOptionsEnvParam(), { ...options });
|
||||
process.env.CODEQL_ACTION_EXTRA_OPTIONS = origExtraOptions;
|
||||
});
|
||||
(0, ava_1.default)("getExtraOptionsEnvParam() fails on invalid JSON", (t) => {
|
||||
const origExtraOptions = process.env.CODEQL_ACTION_EXTRA_OPTIONS;
|
||||
process.env.CODEQL_ACTION_EXTRA_OPTIONS = "{{invalid-json}}";
|
||||
process.env.CODEQL_ACTION_EXTRA_OPTIONS = "{{invalid-json}";
|
||||
t.throws(util.getExtraOptionsEnvParam);
|
||||
process.env.CODEQL_ACTION_EXTRA_OPTIONS = origExtraOptions;
|
||||
});
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -4,6 +4,7 @@ import path from "path";
|
|||
|
||||
import * as core from "@actions/core";
|
||||
import test from "ava";
|
||||
import * as yaml from "js-yaml";
|
||||
import * as sinon from "sinon";
|
||||
|
||||
import * as api from "./api-client";
|
||||
|
|
@ -144,7 +145,7 @@ test("getExtraOptionsEnvParam() succeeds on valid JSON with invalid options (for
|
|||
process.env.CODEQL_ACTION_EXTRA_OPTIONS = origExtraOptions;
|
||||
});
|
||||
|
||||
test("getExtraOptionsEnvParam() succeeds on valid options", (t) => {
|
||||
test("getExtraOptionsEnvParam() succeeds on valid JSON options", (t) => {
|
||||
const origExtraOptions = process.env.CODEQL_ACTION_EXTRA_OPTIONS;
|
||||
|
||||
const options = { database: { init: ["--debug"] } };
|
||||
|
|
@ -155,10 +156,21 @@ test("getExtraOptionsEnvParam() succeeds on valid options", (t) => {
|
|||
process.env.CODEQL_ACTION_EXTRA_OPTIONS = origExtraOptions;
|
||||
});
|
||||
|
||||
test("getExtraOptionsEnvParam() succeeds on valid YAML options", (t) => {
|
||||
const origExtraOptions = process.env.CODEQL_ACTION_EXTRA_OPTIONS;
|
||||
|
||||
const options = { database: { init: ["--debug"] } };
|
||||
process.env.CODEQL_ACTION_EXTRA_OPTIONS = yaml.dump(options);
|
||||
|
||||
t.deepEqual(util.getExtraOptionsEnvParam(), { ...options });
|
||||
|
||||
process.env.CODEQL_ACTION_EXTRA_OPTIONS = origExtraOptions;
|
||||
});
|
||||
|
||||
test("getExtraOptionsEnvParam() fails on invalid JSON", (t) => {
|
||||
const origExtraOptions = process.env.CODEQL_ACTION_EXTRA_OPTIONS;
|
||||
|
||||
process.env.CODEQL_ACTION_EXTRA_OPTIONS = "{{invalid-json}}";
|
||||
process.env.CODEQL_ACTION_EXTRA_OPTIONS = "{{invalid-json}";
|
||||
t.throws(util.getExtraOptionsEnvParam);
|
||||
|
||||
process.env.CODEQL_ACTION_EXTRA_OPTIONS = origExtraOptions;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue