mirror of
https://github.com/github/codeql-action.git
synced 2025-12-23 15:50:11 +08:00
Add tests for the Lua feature flag.
This commit is contained in:
committed by
GitHub
parent
9e9a8428c3
commit
db50adab01
51
lib/codeql.test.js
generated
51
lib/codeql.test.js
generated
@@ -30,6 +30,8 @@ const nock_1 = __importDefault(require("nock"));
|
|||||||
const sinon = __importStar(require("sinon"));
|
const sinon = __importStar(require("sinon"));
|
||||||
const codeql = __importStar(require("./codeql"));
|
const codeql = __importStar(require("./codeql"));
|
||||||
const defaults = __importStar(require("./defaults.json"));
|
const defaults = __importStar(require("./defaults.json"));
|
||||||
|
const feature_flags_1 = require("./feature-flags");
|
||||||
|
const languages_1 = require("./languages");
|
||||||
const logging_1 = require("./logging");
|
const logging_1 = require("./logging");
|
||||||
const testing_utils_1 = require("./testing-utils");
|
const testing_utils_1 = require("./testing-utils");
|
||||||
const util = __importStar(require("./util"));
|
const util = __importStar(require("./util"));
|
||||||
@@ -233,6 +235,55 @@ ava_1.default.beforeEach(() => {
|
|||||||
await codeqlObject.databaseInterpretResults("", [], "", "", "", "");
|
await codeqlObject.databaseInterpretResults("", [], "", "", "", "");
|
||||||
t.true(runnerConstructorStub.firstCall.args[1].includes("--sarif-add-query-help"), "--sarif-add-query-help should be present, but it is absent");
|
t.true(runnerConstructorStub.firstCall.args[1].includes("--sarif-add-query-help"), "--sarif-add-query-help should be present, but it is absent");
|
||||||
});
|
});
|
||||||
|
const stubConfig = {
|
||||||
|
languages: [languages_1.Language.cpp],
|
||||||
|
queries: {},
|
||||||
|
pathsIgnore: [],
|
||||||
|
paths: [],
|
||||||
|
originalUserInput: {},
|
||||||
|
tempDir: "",
|
||||||
|
toolCacheDir: "",
|
||||||
|
codeQLCmd: "",
|
||||||
|
gitHubVersion: {
|
||||||
|
type: util.GitHubVariant.DOTCOM,
|
||||||
|
},
|
||||||
|
dbLocation: "",
|
||||||
|
packs: {},
|
||||||
|
debugMode: false,
|
||||||
|
debugArtifactName: util.DEFAULT_DEBUG_ARTIFACT_NAME,
|
||||||
|
debugDatabaseName: util.DEFAULT_DEBUG_DATABASE_NAME,
|
||||||
|
injectedMlQueries: false,
|
||||||
|
};
|
||||||
|
(0, ava_1.default)("databaseInitCluster() Lua feature flag enabled, but old CLI", async (t) => {
|
||||||
|
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||||
|
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||||
|
sinon.stub(codeqlObject, "getVersion").resolves("2.9.0");
|
||||||
|
await codeqlObject.databaseInitCluster(stubConfig, "", undefined, undefined, (0, feature_flags_1.createFeatureFlags)([feature_flags_1.FeatureFlag.LuaTracerConfigEnabled]));
|
||||||
|
t.false(runnerConstructorStub.firstCall.args[1].includes("--internal-use-lua-tracing"), "--internal-use-lua-tracing should be absent, but it is present");
|
||||||
|
t.false(runnerConstructorStub.firstCall.args[1].includes("--no-internal-use-lua-tracing"), "--no-internal-use-lua-tracing should be absent, but it is present");
|
||||||
|
});
|
||||||
|
(0, ava_1.default)("databaseInitCluster() Lua feature flag disabled, with old CLI", async (t) => {
|
||||||
|
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||||
|
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||||
|
sinon.stub(codeqlObject, "getVersion").resolves("2.9.0");
|
||||||
|
await codeqlObject.databaseInitCluster(stubConfig, "", undefined, undefined, (0, feature_flags_1.createFeatureFlags)([]));
|
||||||
|
t.false(runnerConstructorStub.firstCall.args[1].includes("--internal-use-lua-tracing"), "--internal-use-lua-tracing should be absent, but it is present");
|
||||||
|
t.false(runnerConstructorStub.firstCall.args[1].includes("--no-internal-use-lua-tracing"), "--no-internal-use-lua-tracing should be absent, but it is present");
|
||||||
|
});
|
||||||
|
(0, ava_1.default)("databaseInitCluster() Lua feature flag enabled, compatible CLI", async (t) => {
|
||||||
|
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||||
|
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||||
|
sinon.stub(codeqlObject, "getVersion").resolves("2.10.0");
|
||||||
|
await codeqlObject.databaseInitCluster(stubConfig, "", undefined, undefined, (0, feature_flags_1.createFeatureFlags)([feature_flags_1.FeatureFlag.LuaTracerConfigEnabled]));
|
||||||
|
t.true(runnerConstructorStub.firstCall.args[1].includes("--internal-use-lua-tracing"), "--internal-use-lua-tracing should be present, but it is absent");
|
||||||
|
});
|
||||||
|
(0, ava_1.default)("databaseInitCluster() Lua feature flag disabled, compatible CLI", async (t) => {
|
||||||
|
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||||
|
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||||
|
sinon.stub(codeqlObject, "getVersion").resolves("2.10.0");
|
||||||
|
await codeqlObject.databaseInitCluster(stubConfig, "", undefined, undefined, (0, feature_flags_1.createFeatureFlags)([]));
|
||||||
|
t.true(runnerConstructorStub.firstCall.args[1].includes("--no-internal-use-lua-tracing"), "--no-internal-use-lua-tracing should be present, but it is absent");
|
||||||
|
});
|
||||||
function stubToolRunnerConstructor() {
|
function stubToolRunnerConstructor() {
|
||||||
const runnerObjectStub = sinon.createStubInstance(toolrunner.ToolRunner);
|
const runnerObjectStub = sinon.createStubInstance(toolrunner.ToolRunner);
|
||||||
runnerObjectStub.exec.resolves(0);
|
runnerObjectStub.exec.resolves(0);
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -7,7 +7,10 @@ import nock from "nock";
|
|||||||
import * as sinon from "sinon";
|
import * as sinon from "sinon";
|
||||||
|
|
||||||
import * as codeql from "./codeql";
|
import * as codeql from "./codeql";
|
||||||
|
import { Config } from "./config-utils";
|
||||||
import * as defaults from "./defaults.json";
|
import * as defaults from "./defaults.json";
|
||||||
|
import { createFeatureFlags, FeatureFlag } from "./feature-flags";
|
||||||
|
import { Language } from "./languages";
|
||||||
import { getRunnerLogger } from "./logging";
|
import { getRunnerLogger } from "./logging";
|
||||||
import { setupTests, setupActionsVars } from "./testing-utils";
|
import { setupTests, setupActionsVars } from "./testing-utils";
|
||||||
import * as util from "./util";
|
import * as util from "./util";
|
||||||
@@ -425,6 +428,118 @@ test("databaseInterpretResults() sets --sarif-add-query-help for 2.7.1", async (
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const stubConfig: Config = {
|
||||||
|
languages: [Language.cpp],
|
||||||
|
queries: {},
|
||||||
|
pathsIgnore: [],
|
||||||
|
paths: [],
|
||||||
|
originalUserInput: {},
|
||||||
|
tempDir: "",
|
||||||
|
toolCacheDir: "",
|
||||||
|
codeQLCmd: "",
|
||||||
|
gitHubVersion: {
|
||||||
|
type: util.GitHubVariant.DOTCOM,
|
||||||
|
} as util.GitHubVersion,
|
||||||
|
dbLocation: "",
|
||||||
|
packs: {},
|
||||||
|
debugMode: false,
|
||||||
|
debugArtifactName: util.DEFAULT_DEBUG_ARTIFACT_NAME,
|
||||||
|
debugDatabaseName: util.DEFAULT_DEBUG_DATABASE_NAME,
|
||||||
|
injectedMlQueries: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
test("databaseInitCluster() Lua feature flag enabled, but old CLI", async (t) => {
|
||||||
|
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||||
|
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||||
|
sinon.stub(codeqlObject, "getVersion").resolves("2.9.0");
|
||||||
|
|
||||||
|
await codeqlObject.databaseInitCluster(
|
||||||
|
stubConfig,
|
||||||
|
"",
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
createFeatureFlags([FeatureFlag.LuaTracerConfigEnabled])
|
||||||
|
);
|
||||||
|
t.false(
|
||||||
|
runnerConstructorStub.firstCall.args[1].includes(
|
||||||
|
"--internal-use-lua-tracing"
|
||||||
|
),
|
||||||
|
"--internal-use-lua-tracing should be absent, but it is present"
|
||||||
|
);
|
||||||
|
t.false(
|
||||||
|
runnerConstructorStub.firstCall.args[1].includes(
|
||||||
|
"--no-internal-use-lua-tracing"
|
||||||
|
),
|
||||||
|
"--no-internal-use-lua-tracing should be absent, but it is present"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("databaseInitCluster() Lua feature flag disabled, with old CLI", async (t) => {
|
||||||
|
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||||
|
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||||
|
sinon.stub(codeqlObject, "getVersion").resolves("2.9.0");
|
||||||
|
|
||||||
|
await codeqlObject.databaseInitCluster(
|
||||||
|
stubConfig,
|
||||||
|
"",
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
createFeatureFlags([])
|
||||||
|
);
|
||||||
|
t.false(
|
||||||
|
runnerConstructorStub.firstCall.args[1].includes(
|
||||||
|
"--internal-use-lua-tracing"
|
||||||
|
),
|
||||||
|
"--internal-use-lua-tracing should be absent, but it is present"
|
||||||
|
);
|
||||||
|
t.false(
|
||||||
|
runnerConstructorStub.firstCall.args[1].includes(
|
||||||
|
"--no-internal-use-lua-tracing"
|
||||||
|
),
|
||||||
|
"--no-internal-use-lua-tracing should be absent, but it is present"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("databaseInitCluster() Lua feature flag enabled, compatible CLI", async (t) => {
|
||||||
|
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||||
|
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||||
|
sinon.stub(codeqlObject, "getVersion").resolves("2.10.0");
|
||||||
|
|
||||||
|
await codeqlObject.databaseInitCluster(
|
||||||
|
stubConfig,
|
||||||
|
"",
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
createFeatureFlags([FeatureFlag.LuaTracerConfigEnabled])
|
||||||
|
);
|
||||||
|
t.true(
|
||||||
|
runnerConstructorStub.firstCall.args[1].includes(
|
||||||
|
"--internal-use-lua-tracing"
|
||||||
|
),
|
||||||
|
"--internal-use-lua-tracing should be present, but it is absent"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("databaseInitCluster() Lua feature flag disabled, compatible CLI", async (t) => {
|
||||||
|
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||||
|
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||||
|
sinon.stub(codeqlObject, "getVersion").resolves("2.10.0");
|
||||||
|
|
||||||
|
await codeqlObject.databaseInitCluster(
|
||||||
|
stubConfig,
|
||||||
|
"",
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
createFeatureFlags([])
|
||||||
|
);
|
||||||
|
t.true(
|
||||||
|
runnerConstructorStub.firstCall.args[1].includes(
|
||||||
|
"--no-internal-use-lua-tracing"
|
||||||
|
),
|
||||||
|
"--no-internal-use-lua-tracing should be present, but it is absent"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
function stubToolRunnerConstructor(): sinon.SinonStub<
|
function stubToolRunnerConstructor(): sinon.SinonStub<
|
||||||
any[],
|
any[],
|
||||||
toolrunner.ToolRunner
|
toolrunner.ToolRunner
|
||||||
|
|||||||
Reference in New Issue
Block a user