Add additional tests for database finalize behavior

This commit is contained in:
Henry Mercer 2023-07-20 18:41:28 +01:00
parent e94e15d8dd
commit c84418936e
3 changed files with 62 additions and 1 deletions

24
lib/codeql.test.js generated
View file

@ -718,6 +718,30 @@ for (const { featureEnabled, codeqlVersion, flagPassed, negativeFlagPassed, } of
"https://gh.io/troubleshooting-code-scanning/no-source-code-seen-during-build",
});
});
(0, ava_1.default)("database finalize overrides no code found error on CodeQL 2.11.6", async (t) => {
stubToolRunnerConstructor(32);
const codeqlObject = await codeql.getCodeQLForTesting();
sinon.stub(codeqlObject, "getVersion").resolves("2.11.6");
// safeWhich throws because of the test CodeQL object.
sinon.stub(safeWhich, "safeWhich").resolves("");
await t.throwsAsync(async () => await codeqlObject.finalizeDatabase("", "", ""), {
message: "No code found during the build. Please see: " +
"https://gh.io/troubleshooting-code-scanning/no-source-code-seen-during-build",
});
});
(0, ava_1.default)("database finalize does not override no code found error on CodeQL 2.12.4", async (t) => {
const cliMessage = "CodeQL did not detect any code written in languages supported by CodeQL. Review our troubleshooting guide at " +
"https://gh.io/troubleshooting-code-scanning/no-source-code-seen-during-build.";
stubToolRunnerConstructor(32, cliMessage);
const codeqlObject = await codeql.getCodeQLForTesting();
sinon.stub(codeqlObject, "getVersion").resolves("2.12.4");
// safeWhich throws because of the test CodeQL object.
sinon.stub(safeWhich, "safeWhich").resolves("");
await t.throwsAsync(async () => await codeqlObject.finalizeDatabase("", "", ""), {
message: "Failure invoking codeql-for-testing with arguments database,finalize,--finalize-dataset,,,.\n" +
`Exit code 32 and error was:\n${cliMessage}`,
});
});
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

View file

@ -1157,6 +1157,43 @@ test("database finalize recognises JavaScript no code found error on CodeQL 2.11
);
});
test("database finalize overrides no code found error on CodeQL 2.11.6", async (t) => {
stubToolRunnerConstructor(32);
const codeqlObject = await codeql.getCodeQLForTesting();
sinon.stub(codeqlObject, "getVersion").resolves("2.11.6");
// safeWhich throws because of the test CodeQL object.
sinon.stub(safeWhich, "safeWhich").resolves("");
await t.throwsAsync(
async () => await codeqlObject.finalizeDatabase("", "", ""),
{
message:
"No code found during the build. Please see: " +
"https://gh.io/troubleshooting-code-scanning/no-source-code-seen-during-build",
}
);
});
test("database finalize does not override no code found error on CodeQL 2.12.4", async (t) => {
const cliMessage =
"CodeQL did not detect any code written in languages supported by CodeQL. Review our troubleshooting guide at " +
"https://gh.io/troubleshooting-code-scanning/no-source-code-seen-during-build.";
stubToolRunnerConstructor(32, cliMessage);
const codeqlObject = await codeql.getCodeQLForTesting();
sinon.stub(codeqlObject, "getVersion").resolves("2.12.4");
// safeWhich throws because of the test CodeQL object.
sinon.stub(safeWhich, "safeWhich").resolves("");
await t.throwsAsync(
async () => await codeqlObject.finalizeDatabase("", "", ""),
{
message:
"Failure invoking codeql-for-testing with arguments database,finalize,--finalize-dataset,,,.\n" +
`Exit code 32 and error was:\n${cliMessage}`,
}
);
});
export function stubToolRunnerConstructor(
exitCode: number = 0,
stderr?: string