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
Loading…
Add table
Add a link
Reference in a new issue