mirror of
https://github.com/github/codeql-action.git
synced 2026-01-03 13:10:06 +08:00
Add test for using default version with no requested URL on Dotcom
This commit is contained in:
45
lib/codeql.test.js
generated
45
lib/codeql.test.js
generated
@@ -34,6 +34,7 @@ const yaml = __importStar(require("js-yaml"));
|
||||
const nock_1 = __importDefault(require("nock"));
|
||||
const sinon = __importStar(require("sinon"));
|
||||
const actionsUtil = __importStar(require("./actions-util"));
|
||||
const api = __importStar(require("./api-client"));
|
||||
const codeql = __importStar(require("./codeql"));
|
||||
const defaults = __importStar(require("./defaults.json")); // Referenced from codeql-action-sync-tool!
|
||||
const feature_flags_1 = require("./feature-flags");
|
||||
@@ -107,9 +108,11 @@ async function mockDownloadApi({ apiDetails = sampleApiDetails, isPinned, tagNam
|
||||
.replyWithFile(200, path_1.default.join(__dirname, `/../src/testdata/codeql-bundle${isPinned ? "-pinned" : ""}.tar.gz`));
|
||||
return `${baseUrl}${relativeUrl}`;
|
||||
}
|
||||
async function installIntoToolcache({ apiDetails = sampleApiDetails, isPinned, tagName, tmpDir, }) {
|
||||
async function installIntoToolcache({ apiDetails = sampleApiDetails, cliVersion, isPinned, tagName, tmpDir, }) {
|
||||
const url = await mockDownloadApi({ apiDetails, isPinned, tagName });
|
||||
await codeql.setupCodeQL(url, apiDetails, tmpDir, util.GitHubVariant.DOTCOM, false, SAMPLE_DEFAULT_CLI_VERSION, (0, logging_1.getRunnerLogger)(true), false);
|
||||
await codeql.setupCodeQL(cliVersion !== undefined ? undefined : url, apiDetails, tmpDir, util.GitHubVariant.GHES, false, cliVersion !== undefined
|
||||
? { cliVersion, tagName, variant: util.GitHubVariant.GHES }
|
||||
: SAMPLE_DEFAULT_CLI_VERSION, (0, logging_1.getRunnerLogger)(true), false);
|
||||
}
|
||||
(0, ava_1.default)("downloads and caches explicitly requested bundles that aren't in the toolcache", async (t) => {
|
||||
await util.withTmpDir(async (tmpDir) => {
|
||||
@@ -144,6 +147,44 @@ async function installIntoToolcache({ apiDetails = sampleApiDetails, isPinned, t
|
||||
t.deepEqual(result.toolsVersion, "0.0.0-20200610");
|
||||
});
|
||||
});
|
||||
for (const isCached of [true, false]) {
|
||||
(0, ava_1.default)(`uses default version on Dotcom when default version bundle is ${isCached ? "" : "not "}cached`, async (t) => {
|
||||
await util.withTmpDir(async (tmpDir) => {
|
||||
(0, testing_utils_1.setupActionsVars)(tmpDir, tmpDir);
|
||||
const tagName = `codeql-bundle-20230101`;
|
||||
if (isCached) {
|
||||
await installIntoToolcache({
|
||||
cliVersion: SAMPLE_DEFAULT_CLI_VERSION.cliVersion,
|
||||
tagName,
|
||||
isPinned: true,
|
||||
tmpDir,
|
||||
});
|
||||
}
|
||||
else {
|
||||
await mockDownloadApi({
|
||||
tagName,
|
||||
});
|
||||
sinon.stub(api, "getApiClient").value(() => ({
|
||||
repos: {
|
||||
listReleases: sinon.stub().resolves(undefined),
|
||||
},
|
||||
paginate: sinon.stub().resolves([
|
||||
{
|
||||
assets: [
|
||||
{
|
||||
name: "cli-version-2.0.0.txt",
|
||||
},
|
||||
],
|
||||
tag_name: tagName,
|
||||
},
|
||||
]),
|
||||
}));
|
||||
}
|
||||
const result = await codeql.setupCodeQL(undefined, sampleApiDetails, tmpDir, util.GitHubVariant.DOTCOM, false, SAMPLE_DEFAULT_CLI_VERSION, (0, logging_1.getRunnerLogger)(true), false);
|
||||
t.is(result.toolsVersion, SAMPLE_DEFAULT_CLI_VERSION.cliVersion);
|
||||
});
|
||||
});
|
||||
}
|
||||
for (const variant of [util.GitHubVariant.GHAE, util.GitHubVariant.GHES]) {
|
||||
(0, ava_1.default)(`uses a cached bundle when no tools input is given on ${util.GitHubVariant[variant]}`, async (t) => {
|
||||
await util.withTmpDir(async (tmpDir) => {
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user