Add regression test for double --overwrite
This commit is contained in:
parent
453a95695a
commit
8566d50a79
3 changed files with 54 additions and 1 deletions
18
lib/codeql.test.js
generated
18
lib/codeql.test.js
generated
|
|
@ -613,6 +613,24 @@ for (const { codeqlVersion, flagPassed, githubVersion, negativeFlagPassed, } of
|
|||
"Exit code was 32 and last log line was: line5\\. See the logs for more details\\."),
|
||||
});
|
||||
});
|
||||
(0, ava_1.default)("Avoids duplicating --overwrite flag if specified in CODEQL_ACTION_EXTRA_OPTIONS", async (t) => {
|
||||
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon.stub(codeqlObject, "getVersion").resolves((0, testing_utils_1.makeVersionInfo)("2.12.6"));
|
||||
// safeWhich throws because of the test CodeQL object.
|
||||
sinon.stub(safeWhich, "safeWhich").resolves("");
|
||||
process.env["CODEQL_ACTION_EXTRA_OPTIONS"] =
|
||||
'{ "database": { "init": ["--overwrite"] } }';
|
||||
await codeqlObject.databaseInitCluster(stubConfig, "sourceRoot", undefined, undefined, (0, logging_1.getRunnerLogger)(false));
|
||||
t.true(runnerConstructorStub.calledOnce);
|
||||
const args = runnerConstructorStub.firstCall.args[1];
|
||||
t.is(args.filter((option) => option === "--overwrite").length, 1, "--overwrite should only be passed once");
|
||||
// Clean up
|
||||
const configArg = args.find((arg) => arg.startsWith("--codescanning-config="));
|
||||
t.truthy(configArg, "Should have injected a codescanning config");
|
||||
const configFile = configArg.split("=")[1];
|
||||
await (0, del_1.default)(configFile, { force: true });
|
||||
});
|
||||
function stubToolRunnerConstructor(exitCode = 0, stderr) {
|
||||
const runnerObjectStub = sinon.createStubInstance(toolrunner.ToolRunner);
|
||||
const runnerConstructorStub = sinon.stub(toolrunner, "ToolRunner");
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -976,6 +976,41 @@ test("runTool outputs last line of stderr if fatal error could not be found", as
|
|||
);
|
||||
});
|
||||
|
||||
test("Avoids duplicating --overwrite flag if specified in CODEQL_ACTION_EXTRA_OPTIONS", async (t) => {
|
||||
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionInfo("2.12.6"));
|
||||
// safeWhich throws because of the test CodeQL object.
|
||||
sinon.stub(safeWhich, "safeWhich").resolves("");
|
||||
|
||||
process.env["CODEQL_ACTION_EXTRA_OPTIONS"] =
|
||||
'{ "database": { "init": ["--overwrite"] } }';
|
||||
|
||||
await codeqlObject.databaseInitCluster(
|
||||
stubConfig,
|
||||
"sourceRoot",
|
||||
undefined,
|
||||
undefined,
|
||||
getRunnerLogger(false),
|
||||
);
|
||||
|
||||
t.true(runnerConstructorStub.calledOnce);
|
||||
const args = runnerConstructorStub.firstCall.args[1] as string[];
|
||||
t.is(
|
||||
args.filter((option: string) => option === "--overwrite").length,
|
||||
1,
|
||||
"--overwrite should only be passed once",
|
||||
);
|
||||
|
||||
// Clean up
|
||||
const configArg = args.find((arg: string) =>
|
||||
arg.startsWith("--codescanning-config="),
|
||||
);
|
||||
t.truthy(configArg, "Should have injected a codescanning config");
|
||||
const configFile = configArg!.split("=")[1];
|
||||
await del(configFile, { force: true });
|
||||
});
|
||||
|
||||
export function stubToolRunnerConstructor(
|
||||
exitCode: number = 0,
|
||||
stderr?: string,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue