Add regression test for a bundle URL without a tag

This commit is contained in:
Henry Mercer
2023-02-03 19:11:40 +00:00
parent b95df0b2e7
commit e0fc1c91b2
3 changed files with 112 additions and 92 deletions

16
lib/codeql.test.js generated
View File

@@ -327,7 +327,11 @@ for (const variant of [util.GitHubVariant.GHAE, util.GitHubVariant.GHES]) {
t.is(cachedVersions.length, 2);
});
});
(0, ava_1.default)("download codeql bundle from github ae endpoint", async (t) => {
for (const isBundleVersionInUrl of [true, false]) {
const inclusionString = isBundleVersionInUrl
? "includes"
: "does not include";
(0, ava_1.default)(`download codeql bundle from github ae endpoint (URL ${inclusionString} bundle version)`, async (t) => {
await util.withTmpDir(async (tmpDir) => {
(0, testing_utils_1.setupActionsVars)(tmpDir, tmpDir);
const bundleAssetID = 10;
@@ -337,6 +341,9 @@ for (const variant of [util.GitHubVariant.GHAE, util.GitHubVariant.GHES]) {
? "linux64"
: "osx64";
const codeQLBundleName = `codeql-bundle-${platform}.tar.gz`;
const eventualDownloadUrl = isBundleVersionInUrl
? `https://example.githubenterprise.com/github/codeql-action/releases/download/${defaults.bundleVersion}/${codeQLBundleName}`
: `https://example.githubenterprise.com/api/v3/repos/github/codeql-action/releases/assets/${bundleAssetID}`;
(0, nock_1.default)("https://example.githubenterprise.com")
.get(`/api/v3/enterprise/code-scanning/codeql-bundle/find/${defaults.bundleVersion}`)
.reply(200, {
@@ -345,10 +352,10 @@ for (const variant of [util.GitHubVariant.GHAE, util.GitHubVariant.GHES]) {
(0, nock_1.default)("https://example.githubenterprise.com")
.get(`/api/v3/enterprise/code-scanning/codeql-bundle/download/${bundleAssetID}`)
.reply(200, {
url: `https://example.githubenterprise.com/github/codeql-action/releases/download/${defaults.bundleVersion}/${codeQLBundleName}`,
url: eventualDownloadUrl,
});
(0, nock_1.default)("https://example.githubenterprise.com")
.get(`/github/codeql-action/releases/download/${defaults.bundleVersion}/${codeQLBundleName}`)
.get(eventualDownloadUrl.replace("https://example.githubenterprise.com", ""))
.replyWithFile(200, path_1.default.join(__dirname, `/../src/testdata/codeql-bundle-pinned.tar.gz`));
mockApiDetails(sampleGHAEApiDetails);
sinon.stub(actionsUtil, "isRunningLocalAction").returns(false);
@@ -363,7 +370,8 @@ for (const variant of [util.GitHubVariant.GHAE, util.GitHubVariant.GHES]) {
const cachedVersions = toolcache.findAllVersions("CodeQL");
t.is(cachedVersions.length, 1);
});
});
});
}
(0, ava_1.default)("getExtraOptions works for explicit paths", (t) => {
t.deepEqual(codeql.getExtraOptions({}, ["foo"], []), []);
t.deepEqual(codeql.getExtraOptions({ foo: [42] }, ["foo"], []), ["42"]);

File diff suppressed because one or more lines are too long

View File

@@ -468,7 +468,11 @@ test('downloads bundle if "latest" tools specified but not cached', async (t) =>
});
});
test("download codeql bundle from github ae endpoint", async (t) => {
for (const isBundleVersionInUrl of [true, false]) {
const inclusionString = isBundleVersionInUrl
? "includes"
: "does not include";
test(`download codeql bundle from github ae endpoint (URL ${inclusionString} bundle version)`, async (t) => {
await util.withTmpDir(async (tmpDir) => {
setupActionsVars(tmpDir, tmpDir);
@@ -482,6 +486,10 @@ test("download codeql bundle from github ae endpoint", async (t) => {
: "osx64";
const codeQLBundleName = `codeql-bundle-${platform}.tar.gz`;
const eventualDownloadUrl = isBundleVersionInUrl
? `https://example.githubenterprise.com/github/codeql-action/releases/download/${defaults.bundleVersion}/${codeQLBundleName}`
: `https://example.githubenterprise.com/api/v3/repos/github/codeql-action/releases/assets/${bundleAssetID}`;
nock("https://example.githubenterprise.com")
.get(
`/api/v3/enterprise/code-scanning/codeql-bundle/find/${defaults.bundleVersion}`
@@ -495,12 +503,15 @@ test("download codeql bundle from github ae endpoint", async (t) => {
`/api/v3/enterprise/code-scanning/codeql-bundle/download/${bundleAssetID}`
)
.reply(200, {
url: `https://example.githubenterprise.com/github/codeql-action/releases/download/${defaults.bundleVersion}/${codeQLBundleName}`,
url: eventualDownloadUrl,
});
nock("https://example.githubenterprise.com")
.get(
`/github/codeql-action/releases/download/${defaults.bundleVersion}/${codeQLBundleName}`
eventualDownloadUrl.replace(
"https://example.githubenterprise.com",
""
)
)
.replyWithFile(
200,
@@ -532,7 +543,8 @@ test("download codeql bundle from github ae endpoint", async (t) => {
const cachedVersions = toolcache.findAllVersions("CodeQL");
t.is(cachedVersions.length, 1);
});
});
});
}
test("getExtraOptions works for explicit paths", (t) => {
t.deepEqual(codeql.getExtraOptions({}, ["foo"], []), []);