Move makeVersionOutput to testing-utils.js
This commit is contained in:
parent
a402be8739
commit
e827ad5b71
18 changed files with 110 additions and 114 deletions
2
lib/analyze.test.js
generated
2
lib/analyze.test.js
generated
|
|
@ -214,7 +214,7 @@ const util = __importStar(require("./util"));
|
|||
});
|
||||
function mockCodeQL() {
|
||||
return {
|
||||
getVersion: async () => (0, codeql_1.makeVersionOutput)("1.0.0"),
|
||||
getVersion: async () => (0, testing_utils_1.makeVersionOutput)("1.0.0"),
|
||||
databaseRunQueries: sinon.spy(),
|
||||
databaseInterpretResults: async () => "",
|
||||
databasePrintBaseline: async () => "",
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
29
lib/codeql.js
generated
29
lib/codeql.js
generated
|
|
@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getGeneratedCodeScanningConfigPath = exports.getTrapCachingExtractorConfigArgsForLang = exports.getTrapCachingExtractorConfigArgs = exports.getExtraOptions = exports.getCodeQLForCmd = exports.getCodeQLForTesting = exports.getCachedCodeQL = exports.setCodeQL = exports.makeVersionOutput = exports.getCodeQL = exports.setupCodeQL = exports.CODEQL_VERSION_LANGUAGE_ALIASING = exports.CODEQL_VERSION_LANGUAGE_BASELINE_CONFIG = exports.CODEQL_VERSION_RESOLVE_ENVIRONMENT = exports.CODEQL_VERSION_DIAGNOSTICS_EXPORT_FIXED = exports.CODEQL_VERSION_BETTER_NO_CODE_ERROR_MESSAGE = exports.CODEQL_VERSION_INIT_WITH_QLCONFIG = exports.CODEQL_VERSION_EXPORT_CODE_SCANNING_CONFIG = exports.CODEQL_VERSION_SECURITY_EXPERIMENTAL_SUITE = exports.CommandInvocationError = void 0;
|
||||
exports.getGeneratedCodeScanningConfigPath = exports.getTrapCachingExtractorConfigArgsForLang = exports.getTrapCachingExtractorConfigArgs = exports.getExtraOptions = exports.getCodeQLForCmd = exports.getCodeQLForTesting = exports.getCachedCodeQL = exports.setCodeQL = exports.getCodeQL = exports.setupCodeQL = exports.CODEQL_VERSION_LANGUAGE_ALIASING = exports.CODEQL_VERSION_LANGUAGE_BASELINE_CONFIG = exports.CODEQL_VERSION_RESOLVE_ENVIRONMENT = exports.CODEQL_VERSION_DIAGNOSTICS_EXPORT_FIXED = exports.CODEQL_VERSION_BETTER_NO_CODE_ERROR_MESSAGE = exports.CODEQL_VERSION_INIT_WITH_QLCONFIG = exports.CODEQL_VERSION_EXPORT_CODE_SCANNING_CONFIG = exports.CODEQL_VERSION_SECURITY_EXPERIMENTAL_SUITE = exports.CommandInvocationError = void 0;
|
||||
const fs = __importStar(require("fs"));
|
||||
const path = __importStar(require("path"));
|
||||
const core = __importStar(require("@actions/core"));
|
||||
|
|
@ -174,21 +174,6 @@ function resolveFunction(partialCodeql, methodName, defaultImplementation) {
|
|||
}
|
||||
return partialCodeql[methodName];
|
||||
}
|
||||
/**
|
||||
* Constructs a `VersionOutput` object for testing purposes only.
|
||||
*/
|
||||
const makeVersionOutput = (version) => ({
|
||||
productName: "CodeQL",
|
||||
vendor: "GitHub",
|
||||
sha: "",
|
||||
branches: [],
|
||||
copyright: "",
|
||||
unpackedLocation: "",
|
||||
configFileLocation: "",
|
||||
configFileFound: false,
|
||||
version,
|
||||
});
|
||||
exports.makeVersionOutput = makeVersionOutput;
|
||||
/**
|
||||
* Set the functionality for CodeQL methods. Only for use in tests.
|
||||
*
|
||||
|
|
@ -198,7 +183,17 @@ exports.makeVersionOutput = makeVersionOutput;
|
|||
function setCodeQL(partialCodeql) {
|
||||
cachedCodeQL = {
|
||||
getPath: resolveFunction(partialCodeql, "getPath", () => "/tmp/dummy-path"),
|
||||
getVersion: resolveFunction(partialCodeql, "getVersion", () => new Promise((resolve) => resolve((0, exports.makeVersionOutput)("1.0.0")))),
|
||||
getVersion: resolveFunction(partialCodeql, "getVersion", () => new Promise((resolve) => resolve({
|
||||
productName: "CodeQL",
|
||||
vendor: "GitHub",
|
||||
sha: "",
|
||||
branches: [],
|
||||
copyright: "",
|
||||
unpackedLocation: "",
|
||||
configFileLocation: "",
|
||||
configFileFound: false,
|
||||
version: "1.0.0",
|
||||
}))),
|
||||
printVersion: resolveFunction(partialCodeql, "printVersion"),
|
||||
databaseInitCluster: resolveFunction(partialCodeql, "databaseInitCluster"),
|
||||
runAutobuild: resolveFunction(partialCodeql, "runAutobuild"),
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
40
lib/codeql.test.js
generated
40
lib/codeql.test.js
generated
|
|
@ -379,7 +379,7 @@ for (const isBundleVersionInUrl of [true, false]) {
|
|||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon
|
||||
.stub(codeqlObject, "getVersion")
|
||||
.resolves(codeql.makeVersionOutput("2.10.5"));
|
||||
.resolves((0, testing_utils_1.makeVersionOutput)("2.10.5"));
|
||||
// safeWhich throws because of the test CodeQL object.
|
||||
sinon.stub(safeWhich, "safeWhich").resolves("");
|
||||
const thisStubConfig = {
|
||||
|
|
@ -405,7 +405,7 @@ const injectedConfigMacro = ava_1.default.macro({
|
|||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon
|
||||
.stub(codeqlObject, "getVersion")
|
||||
.resolves(codeql.makeVersionOutput(feature_flags_1.featureConfig[feature_flags_1.Feature.CliConfigFileEnabled].minimumVersion ||
|
||||
.resolves((0, testing_utils_1.makeVersionOutput)(feature_flags_1.featureConfig[feature_flags_1.Feature.CliConfigFileEnabled].minimumVersion ||
|
||||
"1.0.0"));
|
||||
const thisStubConfig = {
|
||||
...stubConfig,
|
||||
|
|
@ -549,9 +549,7 @@ const injectedConfigMacro = ava_1.default.macro({
|
|||
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
// stubbed version doesn't matter. It just needs to be valid semver.
|
||||
sinon
|
||||
.stub(codeqlObject, "getVersion")
|
||||
.resolves(codeql.makeVersionOutput("0.0.0"));
|
||||
sinon.stub(codeqlObject, "getVersion").resolves((0, testing_utils_1.makeVersionOutput)("0.0.0"));
|
||||
await codeqlObject.databaseInitCluster({ ...stubConfig, tempDir }, "", undefined, (0, testing_utils_1.createFeatures)([]), "/path/to/qlconfig.yml", (0, logging_1.getRunnerLogger)(true));
|
||||
const args = runnerConstructorStub.firstCall.args[1];
|
||||
// should not have used a config file
|
||||
|
|
@ -568,7 +566,7 @@ const injectedConfigMacro = ava_1.default.macro({
|
|||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon
|
||||
.stub(codeqlObject, "getVersion")
|
||||
.resolves(codeql.makeVersionOutput(codeql.CODEQL_VERSION_INIT_WITH_QLCONFIG));
|
||||
.resolves((0, testing_utils_1.makeVersionOutput)(codeql.CODEQL_VERSION_INIT_WITH_QLCONFIG));
|
||||
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));
|
||||
const args = runnerConstructorStub.firstCall.args[1];
|
||||
// should have used a config file
|
||||
|
|
@ -585,7 +583,7 @@ const injectedConfigMacro = ava_1.default.macro({
|
|||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon
|
||||
.stub(codeqlObject, "getVersion")
|
||||
.resolves(codeql.makeVersionOutput("2.12.2"));
|
||||
.resolves((0, testing_utils_1.makeVersionOutput)("2.12.2"));
|
||||
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));
|
||||
const args = runnerConstructorStub.firstCall.args[1];
|
||||
// should have used a config file
|
||||
|
|
@ -602,7 +600,7 @@ const injectedConfigMacro = ava_1.default.macro({
|
|||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon
|
||||
.stub(codeqlObject, "getVersion")
|
||||
.resolves(codeql.makeVersionOutput(codeql.CODEQL_VERSION_INIT_WITH_QLCONFIG));
|
||||
.resolves((0, testing_utils_1.makeVersionOutput)(codeql.CODEQL_VERSION_INIT_WITH_QLCONFIG));
|
||||
await codeqlObject.databaseInitCluster({ ...stubConfig, tempDir }, "", undefined, (0, testing_utils_1.createFeatures)([feature_flags_1.Feature.CliConfigFileEnabled]), undefined, // undefined qlconfigFile
|
||||
(0, logging_1.getRunnerLogger)(true));
|
||||
const args = runnerConstructorStub.firstCall.args[1];
|
||||
|
|
@ -613,9 +611,7 @@ const injectedConfigMacro = ava_1.default.macro({
|
|||
(0, ava_1.default)("databaseInterpretResults() sets --sarif-add-baseline-file-info for 2.11.3", async (t) => {
|
||||
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon
|
||||
.stub(codeqlObject, "getVersion")
|
||||
.resolves(codeql.makeVersionOutput("2.11.3"));
|
||||
sinon.stub(codeqlObject, "getVersion").resolves((0, testing_utils_1.makeVersionOutput)("2.11.3"));
|
||||
// safeWhich throws because of the test CodeQL object.
|
||||
sinon.stub(safeWhich, "safeWhich").resolves("");
|
||||
await codeqlObject.databaseInterpretResults("", [], "", "", "", "-v", "", stubConfig, (0, testing_utils_1.createFeatures)([]), (0, logging_1.getRunnerLogger)(true));
|
||||
|
|
@ -624,9 +620,7 @@ const injectedConfigMacro = ava_1.default.macro({
|
|||
(0, ava_1.default)("databaseInterpretResults() does not set --sarif-add-baseline-file-info for 2.11.2", async (t) => {
|
||||
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon
|
||||
.stub(codeqlObject, "getVersion")
|
||||
.resolves(codeql.makeVersionOutput("2.11.2"));
|
||||
sinon.stub(codeqlObject, "getVersion").resolves((0, testing_utils_1.makeVersionOutput)("2.11.2"));
|
||||
// safeWhich throws because of the test CodeQL object.
|
||||
sinon.stub(safeWhich, "safeWhich").resolves("");
|
||||
await codeqlObject.databaseInterpretResults("", [], "", "", "", "-v", "", stubConfig, (0, testing_utils_1.createFeatures)([]), (0, logging_1.getRunnerLogger)(true));
|
||||
|
|
@ -662,7 +656,7 @@ for (const { featureEnabled, codeqlVersion, flagPassed, negativeFlagPassed, } of
|
|||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon
|
||||
.stub(codeqlObject, "getVersion")
|
||||
.resolves(codeql.makeVersionOutput(codeqlVersion));
|
||||
.resolves((0, testing_utils_1.makeVersionOutput)(codeqlVersion));
|
||||
// safeWhich throws because of the test CodeQL object.
|
||||
sinon.stub(safeWhich, "safeWhich").resolves("");
|
||||
await codeqlObject.databaseInterpretResults("", [], "", "", "", "-v", "", stubConfig, (0, testing_utils_1.createFeatures)(featureEnabled ? [feature_flags_1.Feature.AnalysisSummaryV2Enabled] : []), (0, logging_1.getRunnerLogger)(true));
|
||||
|
|
@ -676,9 +670,7 @@ for (const { featureEnabled, codeqlVersion, flagPassed, negativeFlagPassed, } of
|
|||
2020-09-07T17:39:53.9052444Z [2020-09-07 17:39:53] [build-err] No JavaScript or TypeScript code found.
|
||||
2020-09-07T17:39:53.9251124Z [2020-09-07 17:39:53] [ERROR] Spawned process exited abnormally (code 255; tried to run: [/opt/hostedtoolcache/CodeQL/0.0.0-20200630/x64/codeql/javascript/tools/autobuild.sh])`);
|
||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon
|
||||
.stub(codeqlObject, "getVersion")
|
||||
.resolves(codeql.makeVersionOutput("2.11.6"));
|
||||
sinon.stub(codeqlObject, "getVersion").resolves((0, testing_utils_1.makeVersionOutput)("2.11.6"));
|
||||
// safeWhich throws because of the test CodeQL object.
|
||||
sinon.stub(safeWhich, "safeWhich").resolves("");
|
||||
await t.throwsAsync(async () => await codeqlObject.finalizeDatabase("", "", ""), {
|
||||
|
|
@ -689,9 +681,7 @@ for (const { featureEnabled, codeqlVersion, flagPassed, negativeFlagPassed, } of
|
|||
(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(codeql.makeVersionOutput("2.11.6"));
|
||||
sinon.stub(codeqlObject, "getVersion").resolves((0, testing_utils_1.makeVersionOutput)("2.11.6"));
|
||||
// safeWhich throws because of the test CodeQL object.
|
||||
sinon.stub(safeWhich, "safeWhich").resolves("");
|
||||
await t.throwsAsync(async () => await codeqlObject.finalizeDatabase("", "", ""), {
|
||||
|
|
@ -704,9 +694,7 @@ for (const { featureEnabled, codeqlVersion, flagPassed, negativeFlagPassed, } of
|
|||
"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(codeql.makeVersionOutput("2.12.4"));
|
||||
sinon.stub(codeqlObject, "getVersion").resolves((0, testing_utils_1.makeVersionOutput)("2.12.4"));
|
||||
// safeWhich throws because of the test CodeQL object.
|
||||
sinon.stub(safeWhich, "safeWhich").resolves("");
|
||||
await t.throwsAsync(async () => await codeqlObject.finalizeDatabase("db", "--threads=2", "--ram=2048"), {
|
||||
|
|
@ -721,9 +709,7 @@ for (const { featureEnabled, codeqlVersion, flagPassed, negativeFlagPassed, } of
|
|||
`${heapError}\n${datasetImportError}.`;
|
||||
stubToolRunnerConstructor(32, cliStderr);
|
||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon
|
||||
.stub(codeqlObject, "getVersion")
|
||||
.resolves(codeql.makeVersionOutput("2.12.4"));
|
||||
sinon.stub(codeqlObject, "getVersion").resolves((0, testing_utils_1.makeVersionOutput)("2.12.4"));
|
||||
// safeWhich throws because of the test CodeQL object.
|
||||
sinon.stub(safeWhich, "safeWhich").resolves("");
|
||||
await t.throwsAsync(async () => await codeqlObject.finalizeDatabase("db", "--threads=2", "--ram=2048"), {
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
4
lib/config-utils.test.js
generated
4
lib/config-utils.test.js
generated
|
|
@ -1177,7 +1177,7 @@ const calculateAugmentationErrorMacro = ava_1.default.macro({
|
|||
});
|
||||
const codeQL = (0, codeql_1.setCodeQL)({
|
||||
packDownload: packDownloadStub,
|
||||
getVersion: () => Promise.resolve((0, codeql_1.makeVersionOutput)("2.10.5")),
|
||||
getVersion: () => Promise.resolve((0, testing_utils_1.makeVersionOutput)("2.10.5")),
|
||||
});
|
||||
// packs are supplied for go, java, and python
|
||||
// analyzed languages are java, javascript, and python
|
||||
|
|
@ -1221,7 +1221,7 @@ const calculateAugmentationErrorMacro = ava_1.default.macro({
|
|||
},
|
||||
]);
|
||||
const codeQL = (0, codeql_1.setCodeQL)({
|
||||
getVersion: () => Promise.resolve((0, codeql_1.makeVersionOutput)("2.10.4")),
|
||||
getVersion: () => Promise.resolve((0, testing_utils_1.makeVersionOutput)("2.10.4")),
|
||||
});
|
||||
await t.throwsAsync(async () => {
|
||||
return await configUtils.downloadPacks(codeQL, [languages_1.Language.javascript, languages_1.Language.java, languages_1.Language.python], {}, sampleApiDetails, registriesInput, tmpDir, logger);
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
19
lib/testing-utils.js
generated
19
lib/testing-utils.js
generated
|
|
@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.mockBundleDownloadApi = exports.createFeatures = exports.mockCodeQLVersion = exports.mockLanguagesInRepo = exports.mockFeatureFlagApiEndpoint = exports.getRecordingLogger = exports.setupActionsVars = exports.setupTests = exports.SAMPLE_DEFAULT_CLI_VERSION = exports.SAMPLE_DOTCOM_API_DETAILS = void 0;
|
||||
exports.mockBundleDownloadApi = exports.createFeatures = exports.mockCodeQLVersion = exports.makeVersionOutput = exports.mockLanguagesInRepo = exports.mockFeatureFlagApiEndpoint = exports.getRecordingLogger = exports.setupActionsVars = exports.setupTests = exports.SAMPLE_DEFAULT_CLI_VERSION = exports.SAMPLE_DOTCOM_API_DETAILS = void 0;
|
||||
const node_util_1 = require("node:util");
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const github = __importStar(require("@actions/github"));
|
||||
|
|
@ -187,10 +187,25 @@ function mockLanguagesInRepo(languages) {
|
|||
return listLanguages;
|
||||
}
|
||||
exports.mockLanguagesInRepo = mockLanguagesInRepo;
|
||||
/**
|
||||
* Constructs a `VersionOutput` object for testing purposes only.
|
||||
*/
|
||||
const makeVersionOutput = (version) => ({
|
||||
productName: "CodeQL",
|
||||
vendor: "GitHub",
|
||||
sha: "",
|
||||
branches: [],
|
||||
copyright: "",
|
||||
unpackedLocation: "",
|
||||
configFileLocation: "",
|
||||
configFileFound: false,
|
||||
version,
|
||||
});
|
||||
exports.makeVersionOutput = makeVersionOutput;
|
||||
function mockCodeQLVersion(version) {
|
||||
return {
|
||||
async getVersion() {
|
||||
return CodeQL.makeVersionOutput(version);
|
||||
return (0, exports.makeVersionOutput)(version);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
2
lib/trap-caching.test.js
generated
2
lib/trap-caching.test.js
generated
|
|
@ -40,7 +40,7 @@ const util = __importStar(require("./util"));
|
|||
(0, testing_utils_1.setupTests)(ava_1.default);
|
||||
const stubCodeql = (0, codeql_1.setCodeQL)({
|
||||
async getVersion() {
|
||||
return (0, codeql_1.makeVersionOutput)("2.10.3");
|
||||
return (0, testing_utils_1.makeVersionOutput)("2.10.3");
|
||||
},
|
||||
async betterResolveLanguages() {
|
||||
return {
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -12,12 +12,17 @@ import {
|
|||
validateQueryFilters,
|
||||
QueriesStatusReport,
|
||||
} from "./analyze";
|
||||
import { CodeQL, makeVersionOutput, setCodeQL } from "./codeql";
|
||||
import { CodeQL, setCodeQL } from "./codeql";
|
||||
import { Config, QueriesWithSearchPath } from "./config-utils";
|
||||
import { Feature } from "./feature-flags";
|
||||
import { Language } from "./languages";
|
||||
import { getRunnerLogger } from "./logging";
|
||||
import { setupTests, setupActionsVars, createFeatures } from "./testing-utils";
|
||||
import {
|
||||
setupTests,
|
||||
setupActionsVars,
|
||||
createFeatures,
|
||||
makeVersionOutput,
|
||||
} from "./testing-utils";
|
||||
import * as uploadLib from "./upload-lib";
|
||||
import * as util from "./util";
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import {
|
|||
SAMPLE_DOTCOM_API_DETAILS,
|
||||
SAMPLE_DEFAULT_CLI_VERSION,
|
||||
mockBundleDownloadApi,
|
||||
makeVersionOutput,
|
||||
} from "./testing-utils";
|
||||
import * as util from "./util";
|
||||
import { initializeEnvironment } from "./util";
|
||||
|
|
@ -565,7 +566,7 @@ test("databaseInitCluster() without injected codescanning config", async (t) =>
|
|||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon
|
||||
.stub(codeqlObject, "getVersion")
|
||||
.resolves(codeql.makeVersionOutput("2.10.5"));
|
||||
.resolves(makeVersionOutput("2.10.5"));
|
||||
// safeWhich throws because of the test CodeQL object.
|
||||
sinon.stub(safeWhich, "safeWhich").resolves("");
|
||||
|
||||
|
|
@ -610,7 +611,7 @@ const injectedConfigMacro = test.macro({
|
|||
sinon
|
||||
.stub(codeqlObject, "getVersion")
|
||||
.resolves(
|
||||
codeql.makeVersionOutput(
|
||||
makeVersionOutput(
|
||||
featureConfig[Feature.CliConfigFileEnabled].minimumVersion ||
|
||||
"1.0.0",
|
||||
),
|
||||
|
|
@ -836,9 +837,7 @@ test("does not pass a code scanning config or qlconfig file to the CLI when CLI
|
|||
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
// stubbed version doesn't matter. It just needs to be valid semver.
|
||||
sinon
|
||||
.stub(codeqlObject, "getVersion")
|
||||
.resolves(codeql.makeVersionOutput("0.0.0"));
|
||||
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionOutput("0.0.0"));
|
||||
|
||||
await codeqlObject.databaseInitCluster(
|
||||
{ ...stubConfig, tempDir },
|
||||
|
|
@ -870,9 +869,7 @@ test("passes a code scanning config AND qlconfig to the CLI when CLI config pass
|
|||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon
|
||||
.stub(codeqlObject, "getVersion")
|
||||
.resolves(
|
||||
codeql.makeVersionOutput(codeql.CODEQL_VERSION_INIT_WITH_QLCONFIG),
|
||||
);
|
||||
.resolves(makeVersionOutput(codeql.CODEQL_VERSION_INIT_WITH_QLCONFIG));
|
||||
|
||||
await codeqlObject.databaseInitCluster(
|
||||
{ ...stubConfig, tempDir },
|
||||
|
|
@ -904,7 +901,7 @@ test("passes a code scanning config BUT NOT a qlconfig to the CLI when CLI confi
|
|||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon
|
||||
.stub(codeqlObject, "getVersion")
|
||||
.resolves(codeql.makeVersionOutput("2.12.2"));
|
||||
.resolves(makeVersionOutput("2.12.2"));
|
||||
|
||||
await codeqlObject.databaseInitCluster(
|
||||
{ ...stubConfig, tempDir },
|
||||
|
|
@ -939,9 +936,7 @@ test("does not pass a qlconfig to the CLI when it is undefined", async (t: Execu
|
|||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon
|
||||
.stub(codeqlObject, "getVersion")
|
||||
.resolves(
|
||||
codeql.makeVersionOutput(codeql.CODEQL_VERSION_INIT_WITH_QLCONFIG),
|
||||
);
|
||||
.resolves(makeVersionOutput(codeql.CODEQL_VERSION_INIT_WITH_QLCONFIG));
|
||||
|
||||
await codeqlObject.databaseInitCluster(
|
||||
{ ...stubConfig, tempDir },
|
||||
|
|
@ -963,9 +958,7 @@ test("does not pass a qlconfig to the CLI when it is undefined", async (t: Execu
|
|||
test("databaseInterpretResults() sets --sarif-add-baseline-file-info for 2.11.3", async (t) => {
|
||||
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon
|
||||
.stub(codeqlObject, "getVersion")
|
||||
.resolves(codeql.makeVersionOutput("2.11.3"));
|
||||
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionOutput("2.11.3"));
|
||||
// safeWhich throws because of the test CodeQL object.
|
||||
sinon.stub(safeWhich, "safeWhich").resolves("");
|
||||
await codeqlObject.databaseInterpretResults(
|
||||
|
|
@ -991,9 +984,7 @@ test("databaseInterpretResults() sets --sarif-add-baseline-file-info for 2.11.3"
|
|||
test("databaseInterpretResults() does not set --sarif-add-baseline-file-info for 2.11.2", async (t) => {
|
||||
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon
|
||||
.stub(codeqlObject, "getVersion")
|
||||
.resolves(codeql.makeVersionOutput("2.11.2"));
|
||||
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionOutput("2.11.2"));
|
||||
// safeWhich throws because of the test CodeQL object.
|
||||
sinon.stub(safeWhich, "safeWhich").resolves("");
|
||||
await codeqlObject.databaseInterpretResults(
|
||||
|
|
@ -1056,7 +1047,7 @@ for (const {
|
|||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon
|
||||
.stub(codeqlObject, "getVersion")
|
||||
.resolves(codeql.makeVersionOutput(codeqlVersion));
|
||||
.resolves(makeVersionOutput(codeqlVersion));
|
||||
// safeWhich throws because of the test CodeQL object.
|
||||
sinon.stub(safeWhich, "safeWhich").resolves("");
|
||||
await codeqlObject.databaseInterpretResults(
|
||||
|
|
@ -1099,9 +1090,7 @@ test("database finalize recognises JavaScript no code found error on CodeQL 2.11
|
|||
2020-09-07T17:39:53.9251124Z [2020-09-07 17:39:53] [ERROR] Spawned process exited abnormally (code 255; tried to run: [/opt/hostedtoolcache/CodeQL/0.0.0-20200630/x64/codeql/javascript/tools/autobuild.sh])`,
|
||||
);
|
||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon
|
||||
.stub(codeqlObject, "getVersion")
|
||||
.resolves(codeql.makeVersionOutput("2.11.6"));
|
||||
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionOutput("2.11.6"));
|
||||
// safeWhich throws because of the test CodeQL object.
|
||||
sinon.stub(safeWhich, "safeWhich").resolves("");
|
||||
|
||||
|
|
@ -1118,9 +1107,7 @@ 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(codeql.makeVersionOutput("2.11.6"));
|
||||
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionOutput("2.11.6"));
|
||||
// safeWhich throws because of the test CodeQL object.
|
||||
sinon.stub(safeWhich, "safeWhich").resolves("");
|
||||
|
||||
|
|
@ -1140,9 +1127,7 @@ test("database finalize does not override no code found error on CodeQL 2.12.4",
|
|||
"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(codeql.makeVersionOutput("2.12.4"));
|
||||
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionOutput("2.12.4"));
|
||||
// safeWhich throws because of the test CodeQL object.
|
||||
sinon.stub(safeWhich, "safeWhich").resolves("");
|
||||
|
||||
|
|
@ -1167,9 +1152,7 @@ test("runTool summarizes several fatal errors", async (t) => {
|
|||
`${heapError}\n${datasetImportError}.`;
|
||||
stubToolRunnerConstructor(32, cliStderr);
|
||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon
|
||||
.stub(codeqlObject, "getVersion")
|
||||
.resolves(codeql.makeVersionOutput("2.12.4"));
|
||||
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionOutput("2.12.4"));
|
||||
// safeWhich throws because of the test CodeQL object.
|
||||
sinon.stub(safeWhich, "safeWhich").resolves("");
|
||||
|
||||
|
|
|
|||
|
|
@ -443,21 +443,6 @@ function resolveFunction<T>(
|
|||
return partialCodeql[methodName];
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a `VersionOutput` object for testing purposes only.
|
||||
*/
|
||||
export const makeVersionOutput = (version: string): VersionOutput => ({
|
||||
productName: "CodeQL",
|
||||
vendor: "GitHub",
|
||||
sha: "",
|
||||
branches: [],
|
||||
copyright: "",
|
||||
unpackedLocation: "",
|
||||
configFileLocation: "",
|
||||
configFileFound: false,
|
||||
version,
|
||||
});
|
||||
|
||||
/**
|
||||
* Set the functionality for CodeQL methods. Only for use in tests.
|
||||
*
|
||||
|
|
@ -470,7 +455,20 @@ export function setCodeQL(partialCodeql: Partial<CodeQL>): CodeQL {
|
|||
getVersion: resolveFunction(
|
||||
partialCodeql,
|
||||
"getVersion",
|
||||
() => new Promise((resolve) => resolve(makeVersionOutput("1.0.0"))),
|
||||
() =>
|
||||
new Promise((resolve) =>
|
||||
resolve({
|
||||
productName: "CodeQL",
|
||||
vendor: "GitHub",
|
||||
sha: "",
|
||||
branches: [],
|
||||
copyright: "",
|
||||
unpackedLocation: "",
|
||||
configFileLocation: "",
|
||||
configFileFound: false,
|
||||
version: "1.0.0",
|
||||
}),
|
||||
),
|
||||
),
|
||||
printVersion: resolveFunction(partialCodeql, "printVersion"),
|
||||
databaseInitCluster: resolveFunction(partialCodeql, "databaseInitCluster"),
|
||||
|
|
|
|||
|
|
@ -7,12 +7,7 @@ import * as yaml from "js-yaml";
|
|||
import * as sinon from "sinon";
|
||||
|
||||
import * as api from "./api-client";
|
||||
import {
|
||||
getCachedCodeQL,
|
||||
makeVersionOutput,
|
||||
PackDownloadOutput,
|
||||
setCodeQL,
|
||||
} from "./codeql";
|
||||
import { getCachedCodeQL, PackDownloadOutput, setCodeQL } from "./codeql";
|
||||
import * as configUtils from "./config-utils";
|
||||
import { Language } from "./languages";
|
||||
import { getRunnerLogger, Logger } from "./logging";
|
||||
|
|
@ -21,6 +16,7 @@ import {
|
|||
setupTests,
|
||||
createFeatures,
|
||||
mockLanguagesInRepo as mockLanguagesInRepo,
|
||||
makeVersionOutput,
|
||||
} from "./testing-utils";
|
||||
import {
|
||||
GitHubVariant,
|
||||
|
|
|
|||
|
|
@ -208,10 +208,25 @@ export function mockLanguagesInRepo(languages: string[]) {
|
|||
return listLanguages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a `VersionOutput` object for testing purposes only.
|
||||
*/
|
||||
export const makeVersionOutput = (version: string): CodeQL.VersionOutput => ({
|
||||
productName: "CodeQL",
|
||||
vendor: "GitHub",
|
||||
sha: "",
|
||||
branches: [],
|
||||
copyright: "",
|
||||
unpackedLocation: "",
|
||||
configFileLocation: "",
|
||||
configFileFound: false,
|
||||
version,
|
||||
});
|
||||
|
||||
export function mockCodeQLVersion(version: string) {
|
||||
return {
|
||||
async getVersion() {
|
||||
return CodeQL.makeVersionOutput(version);
|
||||
return makeVersionOutput(version);
|
||||
},
|
||||
} as CodeQL.CodeQL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,12 +10,15 @@ import {
|
|||
setCodeQL,
|
||||
getTrapCachingExtractorConfigArgs,
|
||||
getTrapCachingExtractorConfigArgsForLang,
|
||||
makeVersionOutput,
|
||||
} from "./codeql";
|
||||
import * as configUtils from "./config-utils";
|
||||
import { Config } from "./config-utils";
|
||||
import { Language } from "./languages";
|
||||
import { getRecordingLogger, setupTests } from "./testing-utils";
|
||||
import {
|
||||
getRecordingLogger,
|
||||
makeVersionOutput,
|
||||
setupTests,
|
||||
} from "./testing-utils";
|
||||
import {
|
||||
downloadTrapCaches,
|
||||
getLanguagesSupportingCaching,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue