Avoid writing user-config.yaml file while running tests
This commit is contained in:
parent
6ef6e50882
commit
8340258886
3 changed files with 118 additions and 106 deletions
78
lib/codeql.test.js
generated
78
lib/codeql.test.js
generated
|
|
@ -666,46 +666,52 @@ const injectedConfigMacro = ava_1.default.macro({
|
||||||
},
|
},
|
||||||
}, {});
|
}, {});
|
||||||
(0, ava_1.default)("does not pass a code scanning config or qlconfig file to the CLI when CLI config passing is disabled", async (t) => {
|
(0, ava_1.default)("does not pass a code scanning config or qlconfig file to the CLI when CLI config passing is disabled", async (t) => {
|
||||||
const runnerConstructorStub = stubToolRunnerConstructor();
|
await util.withTmpDir(async (tempDir) => {
|
||||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||||
// stubbed version doesn't matter. It just needs to be valid semver.
|
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||||
sinon.stub(codeqlObject, "getVersion").resolves("0.0.0");
|
// stubbed version doesn't matter. It just needs to be valid semver.
|
||||||
await codeqlObject.databaseInitCluster(stubConfig, "", undefined, (0, testing_utils_1.createFeatures)([]), "/path/to/qlconfig.yml", (0, logging_1.getRunnerLogger)(true));
|
sinon.stub(codeqlObject, "getVersion").resolves("0.0.0");
|
||||||
const args = runnerConstructorStub.firstCall.args[1];
|
await codeqlObject.databaseInitCluster({ ...stubConfig, tempDir }, "", undefined, (0, testing_utils_1.createFeatures)([]), "/path/to/qlconfig.yml", (0, logging_1.getRunnerLogger)(true));
|
||||||
// should not have used a config file
|
const args = runnerConstructorStub.firstCall.args[1];
|
||||||
const hasConfigArg = args.some((arg) => arg.startsWith("--codescanning-config="));
|
// should not have used a config file
|
||||||
t.false(hasConfigArg, "Should NOT have injected a codescanning config");
|
const hasConfigArg = args.some((arg) => arg.startsWith("--codescanning-config="));
|
||||||
// should not have passed a qlconfig file
|
t.false(hasConfigArg, "Should NOT have injected a codescanning config");
|
||||||
const hasQlconfigArg = args.some((arg) => arg.startsWith("--qlconfig="));
|
// should not have passed a qlconfig file
|
||||||
t.false(hasQlconfigArg, "Should NOT have passed a qlconfig file");
|
const hasQlconfigArg = args.some((arg) => arg.startsWith("--qlconfig="));
|
||||||
|
t.false(hasQlconfigArg, "Should NOT have passed a qlconfig file");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
(0, ava_1.default)("passes a code scanning config AND qlconfig to the CLI when CLI config passing is enabled", async (t) => {
|
(0, ava_1.default)("passes a code scanning config AND qlconfig to the CLI when CLI config passing is enabled", async (t) => {
|
||||||
const runnerConstructorStub = stubToolRunnerConstructor();
|
await util.withTmpDir(async (tempDir) => {
|
||||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||||
sinon
|
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||||
.stub(codeqlObject, "getVersion")
|
sinon
|
||||||
.resolves(codeql.CODEQL_VERSION_INIT_WITH_QLCONFIG);
|
.stub(codeqlObject, "getVersion")
|
||||||
await codeqlObject.databaseInitCluster(stubConfig, "", undefined, (0, testing_utils_1.createFeatures)([feature_flags_1.Feature.CliConfigFileEnabled]), "/path/to/qlconfig.yml", (0, logging_1.getRunnerLogger)(true));
|
.resolves(codeql.CODEQL_VERSION_INIT_WITH_QLCONFIG);
|
||||||
const args = runnerConstructorStub.firstCall.args[1];
|
await codeqlObject.databaseInitCluster({ ...stubConfig, tempDir }, "", undefined, (0, testing_utils_1.createFeatures)([feature_flags_1.Feature.CliConfigFileEnabled]), "/path/to/qlconfig.yml", (0, logging_1.getRunnerLogger)(true));
|
||||||
// should have used a config file
|
const args = runnerConstructorStub.firstCall.args[1];
|
||||||
const hasCodeScanningConfigArg = args.some((arg) => arg.startsWith("--codescanning-config="));
|
// should have used a config file
|
||||||
t.true(hasCodeScanningConfigArg, "Should have injected a qlconfig");
|
const hasCodeScanningConfigArg = args.some((arg) => arg.startsWith("--codescanning-config="));
|
||||||
// should have passed a qlconfig file
|
t.true(hasCodeScanningConfigArg, "Should have injected a qlconfig");
|
||||||
const hasQlconfigArg = args.some((arg) => arg.startsWith("--qlconfig="));
|
// should have passed a qlconfig file
|
||||||
t.truthy(hasQlconfigArg, "Should have injected a codescanning config");
|
const hasQlconfigArg = args.some((arg) => arg.startsWith("--qlconfig="));
|
||||||
|
t.truthy(hasQlconfigArg, "Should have injected a codescanning config");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
(0, ava_1.default)("passes a code scanning config BUT NOT a qlconfig to the CLI when CLI config passing is enabled", async (t) => {
|
(0, ava_1.default)("passes a code scanning config BUT NOT a qlconfig to the CLI when CLI config passing is enabled", async (t) => {
|
||||||
const runnerConstructorStub = stubToolRunnerConstructor();
|
await util.withTmpDir(async (tempDir) => {
|
||||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||||
sinon.stub(codeqlObject, "getVersion").resolves("2.12.2");
|
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||||
await codeqlObject.databaseInitCluster(stubConfig, "", undefined, (0, testing_utils_1.createFeatures)([feature_flags_1.Feature.CliConfigFileEnabled]), "/path/to/qlconfig.yml", (0, logging_1.getRunnerLogger)(true));
|
sinon.stub(codeqlObject, "getVersion").resolves("2.12.2");
|
||||||
const args = runnerConstructorStub.firstCall.args[1];
|
await codeqlObject.databaseInitCluster({ ...stubConfig, tempDir }, "", undefined, (0, testing_utils_1.createFeatures)([feature_flags_1.Feature.CliConfigFileEnabled]), "/path/to/qlconfig.yml", (0, logging_1.getRunnerLogger)(true));
|
||||||
// should have used a config file
|
const args = runnerConstructorStub.firstCall.args[1];
|
||||||
const hasCodeScanningConfigArg = args.some((arg) => arg.startsWith("--codescanning-config="));
|
// should have used a config file
|
||||||
t.true(hasCodeScanningConfigArg, "Should NOT have injected a qlconfig");
|
const hasCodeScanningConfigArg = args.some((arg) => arg.startsWith("--codescanning-config="));
|
||||||
// should have passed a qlconfig file
|
t.true(hasCodeScanningConfigArg, "Should NOT have injected a qlconfig");
|
||||||
const hasQlconfigArg = args.some((arg) => arg.startsWith("--qlconfig="));
|
// should have passed a qlconfig file
|
||||||
t.false(hasQlconfigArg, "Should have injected a codescanning config");
|
const hasQlconfigArg = args.some((arg) => arg.startsWith("--qlconfig="));
|
||||||
|
t.false(hasQlconfigArg, "Should have injected a codescanning config");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
(0, ava_1.default)("databaseInterpretResults() sets --sarif-add-baseline-file-info for 2.11.3", async (t) => {
|
(0, ava_1.default)("databaseInterpretResults() sets --sarif-add-baseline-file-info for 2.11.3", async (t) => {
|
||||||
const runnerConstructorStub = stubToolRunnerConstructor();
|
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -1003,89 +1003,95 @@ test(
|
||||||
);
|
);
|
||||||
|
|
||||||
test("does not pass a code scanning config or qlconfig file to the CLI when CLI config passing is disabled", async (t: ExecutionContext<unknown>) => {
|
test("does not pass a code scanning config or qlconfig file to the CLI when CLI config passing is disabled", async (t: ExecutionContext<unknown>) => {
|
||||||
const runnerConstructorStub = stubToolRunnerConstructor();
|
await util.withTmpDir(async (tempDir) => {
|
||||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||||
// stubbed version doesn't matter. It just needs to be valid semver.
|
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||||
sinon.stub(codeqlObject, "getVersion").resolves("0.0.0");
|
// stubbed version doesn't matter. It just needs to be valid semver.
|
||||||
|
sinon.stub(codeqlObject, "getVersion").resolves("0.0.0");
|
||||||
|
|
||||||
await codeqlObject.databaseInitCluster(
|
await codeqlObject.databaseInitCluster(
|
||||||
stubConfig,
|
{ ...stubConfig, tempDir },
|
||||||
"",
|
"",
|
||||||
undefined,
|
undefined,
|
||||||
createFeatures([]),
|
createFeatures([]),
|
||||||
"/path/to/qlconfig.yml",
|
"/path/to/qlconfig.yml",
|
||||||
getRunnerLogger(true)
|
getRunnerLogger(true)
|
||||||
);
|
);
|
||||||
|
|
||||||
const args = runnerConstructorStub.firstCall.args[1];
|
const args = runnerConstructorStub.firstCall.args[1];
|
||||||
// should not have used a config file
|
// should not have used a config file
|
||||||
const hasConfigArg = args.some((arg: string) =>
|
const hasConfigArg = args.some((arg: string) =>
|
||||||
arg.startsWith("--codescanning-config=")
|
arg.startsWith("--codescanning-config=")
|
||||||
);
|
);
|
||||||
t.false(hasConfigArg, "Should NOT have injected a codescanning config");
|
t.false(hasConfigArg, "Should NOT have injected a codescanning config");
|
||||||
|
|
||||||
// should not have passed a qlconfig file
|
// should not have passed a qlconfig file
|
||||||
const hasQlconfigArg = args.some((arg: string) =>
|
const hasQlconfigArg = args.some((arg: string) =>
|
||||||
arg.startsWith("--qlconfig=")
|
arg.startsWith("--qlconfig=")
|
||||||
);
|
);
|
||||||
t.false(hasQlconfigArg, "Should NOT have passed a qlconfig file");
|
t.false(hasQlconfigArg, "Should NOT have passed a qlconfig file");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test("passes a code scanning config AND qlconfig to the CLI when CLI config passing is enabled", async (t: ExecutionContext<unknown>) => {
|
test("passes a code scanning config AND qlconfig to the CLI when CLI config passing is enabled", async (t: ExecutionContext<unknown>) => {
|
||||||
const runnerConstructorStub = stubToolRunnerConstructor();
|
await util.withTmpDir(async (tempDir) => {
|
||||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||||
sinon
|
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||||
.stub(codeqlObject, "getVersion")
|
sinon
|
||||||
.resolves(codeql.CODEQL_VERSION_INIT_WITH_QLCONFIG);
|
.stub(codeqlObject, "getVersion")
|
||||||
|
.resolves(codeql.CODEQL_VERSION_INIT_WITH_QLCONFIG);
|
||||||
|
|
||||||
await codeqlObject.databaseInitCluster(
|
await codeqlObject.databaseInitCluster(
|
||||||
stubConfig,
|
{ ...stubConfig, tempDir },
|
||||||
"",
|
"",
|
||||||
undefined,
|
undefined,
|
||||||
createFeatures([Feature.CliConfigFileEnabled]),
|
createFeatures([Feature.CliConfigFileEnabled]),
|
||||||
"/path/to/qlconfig.yml",
|
"/path/to/qlconfig.yml",
|
||||||
getRunnerLogger(true)
|
getRunnerLogger(true)
|
||||||
);
|
);
|
||||||
|
|
||||||
const args = runnerConstructorStub.firstCall.args[1];
|
const args = runnerConstructorStub.firstCall.args[1];
|
||||||
// should have used a config file
|
// should have used a config file
|
||||||
const hasCodeScanningConfigArg = args.some((arg: string) =>
|
const hasCodeScanningConfigArg = args.some((arg: string) =>
|
||||||
arg.startsWith("--codescanning-config=")
|
arg.startsWith("--codescanning-config=")
|
||||||
);
|
);
|
||||||
t.true(hasCodeScanningConfigArg, "Should have injected a qlconfig");
|
t.true(hasCodeScanningConfigArg, "Should have injected a qlconfig");
|
||||||
|
|
||||||
// should have passed a qlconfig file
|
// should have passed a qlconfig file
|
||||||
const hasQlconfigArg = args.some((arg: string) =>
|
const hasQlconfigArg = args.some((arg: string) =>
|
||||||
arg.startsWith("--qlconfig=")
|
arg.startsWith("--qlconfig=")
|
||||||
);
|
);
|
||||||
t.truthy(hasQlconfigArg, "Should have injected a codescanning config");
|
t.truthy(hasQlconfigArg, "Should have injected a codescanning config");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
test("passes a code scanning config BUT NOT a qlconfig to the CLI when CLI config passing is enabled", async (t: ExecutionContext<unknown>) => {
|
test("passes a code scanning config BUT NOT a qlconfig to the CLI when CLI config passing is enabled", async (t: ExecutionContext<unknown>) => {
|
||||||
const runnerConstructorStub = stubToolRunnerConstructor();
|
await util.withTmpDir(async (tempDir) => {
|
||||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||||
sinon.stub(codeqlObject, "getVersion").resolves("2.12.2");
|
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||||
|
sinon.stub(codeqlObject, "getVersion").resolves("2.12.2");
|
||||||
|
|
||||||
await codeqlObject.databaseInitCluster(
|
await codeqlObject.databaseInitCluster(
|
||||||
stubConfig,
|
{ ...stubConfig, tempDir },
|
||||||
"",
|
"",
|
||||||
undefined,
|
undefined,
|
||||||
createFeatures([Feature.CliConfigFileEnabled]),
|
createFeatures([Feature.CliConfigFileEnabled]),
|
||||||
"/path/to/qlconfig.yml",
|
"/path/to/qlconfig.yml",
|
||||||
getRunnerLogger(true)
|
getRunnerLogger(true)
|
||||||
);
|
);
|
||||||
|
|
||||||
const args = runnerConstructorStub.firstCall.args[1] as any[];
|
const args = runnerConstructorStub.firstCall.args[1] as any[];
|
||||||
// should have used a config file
|
// should have used a config file
|
||||||
const hasCodeScanningConfigArg = args.some((arg: string) =>
|
const hasCodeScanningConfigArg = args.some((arg: string) =>
|
||||||
arg.startsWith("--codescanning-config=")
|
arg.startsWith("--codescanning-config=")
|
||||||
);
|
);
|
||||||
t.true(hasCodeScanningConfigArg, "Should NOT have injected a qlconfig");
|
t.true(hasCodeScanningConfigArg, "Should NOT have injected a qlconfig");
|
||||||
|
|
||||||
// should have passed a qlconfig file
|
// should have passed a qlconfig file
|
||||||
const hasQlconfigArg = args.some((arg: string) =>
|
const hasQlconfigArg = args.some((arg: string) =>
|
||||||
arg.startsWith("--qlconfig=")
|
arg.startsWith("--qlconfig=")
|
||||||
);
|
);
|
||||||
t.false(hasQlconfigArg, "Should have injected a codescanning config");
|
t.false(hasQlconfigArg, "Should have injected a codescanning config");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test("databaseInterpretResults() sets --sarif-add-baseline-file-info for 2.11.3", async (t) => {
|
test("databaseInterpretResults() sets --sarif-add-baseline-file-info for 2.11.3", async (t) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue