Add regression test for bundle from different repo
This commit is contained in:
parent
c6ff11c1c4
commit
6d47a7c8b1
3 changed files with 73 additions and 4 deletions
28
lib/codeql.test.js
generated
28
lib/codeql.test.js
generated
|
|
@ -97,7 +97,7 @@ ava_1.default.beforeEach(() => {
|
||||||
* @returns the download URL for the bundle. This can be passed to the tools parameter of
|
* @returns the download URL for the bundle. This can be passed to the tools parameter of
|
||||||
* `codeql.setupCodeQL`.
|
* `codeql.setupCodeQL`.
|
||||||
*/
|
*/
|
||||||
function mockDownloadApi({ apiDetails = sampleApiDetails, isPinned, tagName, }) {
|
function mockDownloadApi({ apiDetails = sampleApiDetails, isPinned, repo = "github/codeql-action", platformSpecific = true, tagName, }) {
|
||||||
const platform = process.platform === "win32"
|
const platform = process.platform === "win32"
|
||||||
? "win64"
|
? "win64"
|
||||||
: process.platform === "linux"
|
: process.platform === "linux"
|
||||||
|
|
@ -105,7 +105,7 @@ function mockDownloadApi({ apiDetails = sampleApiDetails, isPinned, tagName, })
|
||||||
: "osx64";
|
: "osx64";
|
||||||
const baseUrl = apiDetails?.url ?? "https://example.com";
|
const baseUrl = apiDetails?.url ?? "https://example.com";
|
||||||
const relativeUrl = apiDetails
|
const relativeUrl = apiDetails
|
||||||
? `/github/codeql-action/releases/download/${tagName}/codeql-bundle-${platform}.tar.gz`
|
? `/${repo}/releases/download/${tagName}/codeql-bundle${platformSpecific ? `-${platform}` : ""}.tar.gz`
|
||||||
: `/download/${tagName}/codeql-bundle.tar.gz`;
|
: `/download/${tagName}/codeql-bundle.tar.gz`;
|
||||||
(0, nock_1.default)(baseUrl)
|
(0, nock_1.default)(baseUrl)
|
||||||
.get(relativeUrl)
|
.get(relativeUrl)
|
||||||
|
|
@ -372,6 +372,30 @@ for (const isBundleVersionInUrl of [true, false]) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
(0, ava_1.default)("bundle URL from another repo is cached as 0.0.0-bundleVersion", async (t) => {
|
||||||
|
await util.withTmpDir(async (tmpDir) => {
|
||||||
|
(0, testing_utils_1.setupActionsVars)(tmpDir, tmpDir);
|
||||||
|
mockApiDetails(sampleApiDetails);
|
||||||
|
sinon.stub(actionsUtil, "isRunningLocalAction").returns(true);
|
||||||
|
const releasesApiMock = mockReleaseApi({
|
||||||
|
assetNames: ["cli-version-2.12.2.txt"],
|
||||||
|
tagName: "codeql-bundle-20230203",
|
||||||
|
});
|
||||||
|
mockDownloadApi({
|
||||||
|
repo: "dsp-testing/codeql-cli-nightlies",
|
||||||
|
platformSpecific: false,
|
||||||
|
tagName: "codeql-bundle-20230203",
|
||||||
|
});
|
||||||
|
const result = await codeql.setupCodeQL("https://github.com/dsp-testing/codeql-cli-nightlies/releases/download/codeql-bundle-20230203/codeql-bundle.tar.gz", sampleApiDetails, tmpDir, util.GitHubVariant.DOTCOM, false, SAMPLE_DEFAULT_CLI_VERSION, (0, logging_1.getRunnerLogger)(true), false);
|
||||||
|
t.is(result.toolsVersion, "0.0.0-20230203");
|
||||||
|
t.is(result.toolsSource, init_1.ToolsSource.Download);
|
||||||
|
t.true(Number.isInteger(result.toolsDownloadDurationMs));
|
||||||
|
const cachedVersions = toolcache.findAllVersions("CodeQL");
|
||||||
|
t.is(cachedVersions.length, 1);
|
||||||
|
t.is(cachedVersions[0], "0.0.0-20230203");
|
||||||
|
t.false(releasesApiMock.isDone());
|
||||||
|
});
|
||||||
|
});
|
||||||
(0, ava_1.default)("getExtraOptions works for explicit paths", (t) => {
|
(0, ava_1.default)("getExtraOptions works for explicit paths", (t) => {
|
||||||
t.deepEqual(codeql.getExtraOptions({}, ["foo"], []), []);
|
t.deepEqual(codeql.getExtraOptions({}, ["foo"], []), []);
|
||||||
t.deepEqual(codeql.getExtraOptions({ foo: [42] }, ["foo"], []), ["42"]);
|
t.deepEqual(codeql.getExtraOptions({ foo: [42] }, ["foo"], []), ["42"]);
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -87,10 +87,14 @@ test.beforeEach(() => {
|
||||||
function mockDownloadApi({
|
function mockDownloadApi({
|
||||||
apiDetails = sampleApiDetails,
|
apiDetails = sampleApiDetails,
|
||||||
isPinned,
|
isPinned,
|
||||||
|
repo = "github/codeql-action",
|
||||||
|
platformSpecific = true,
|
||||||
tagName,
|
tagName,
|
||||||
}: {
|
}: {
|
||||||
apiDetails?: GitHubApiDetails;
|
apiDetails?: GitHubApiDetails;
|
||||||
isPinned?: boolean;
|
isPinned?: boolean;
|
||||||
|
repo?: string;
|
||||||
|
platformSpecific?: boolean;
|
||||||
tagName: string;
|
tagName: string;
|
||||||
}): string {
|
}): string {
|
||||||
const platform =
|
const platform =
|
||||||
|
|
@ -102,7 +106,9 @@ function mockDownloadApi({
|
||||||
|
|
||||||
const baseUrl = apiDetails?.url ?? "https://example.com";
|
const baseUrl = apiDetails?.url ?? "https://example.com";
|
||||||
const relativeUrl = apiDetails
|
const relativeUrl = apiDetails
|
||||||
? `/github/codeql-action/releases/download/${tagName}/codeql-bundle-${platform}.tar.gz`
|
? `/${repo}/releases/download/${tagName}/codeql-bundle${
|
||||||
|
platformSpecific ? `-${platform}` : ""
|
||||||
|
}.tar.gz`
|
||||||
: `/download/${tagName}/codeql-bundle.tar.gz`;
|
: `/download/${tagName}/codeql-bundle.tar.gz`;
|
||||||
|
|
||||||
nock(baseUrl)
|
nock(baseUrl)
|
||||||
|
|
@ -546,6 +552,45 @@ for (const isBundleVersionInUrl of [true, false]) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test("bundle URL from another repo is cached as 0.0.0-bundleVersion", async (t) => {
|
||||||
|
await util.withTmpDir(async (tmpDir) => {
|
||||||
|
setupActionsVars(tmpDir, tmpDir);
|
||||||
|
|
||||||
|
mockApiDetails(sampleApiDetails);
|
||||||
|
sinon.stub(actionsUtil, "isRunningLocalAction").returns(true);
|
||||||
|
const releasesApiMock = mockReleaseApi({
|
||||||
|
assetNames: ["cli-version-2.12.2.txt"],
|
||||||
|
tagName: "codeql-bundle-20230203",
|
||||||
|
});
|
||||||
|
mockDownloadApi({
|
||||||
|
repo: "dsp-testing/codeql-cli-nightlies",
|
||||||
|
platformSpecific: false,
|
||||||
|
tagName: "codeql-bundle-20230203",
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await codeql.setupCodeQL(
|
||||||
|
"https://github.com/dsp-testing/codeql-cli-nightlies/releases/download/codeql-bundle-20230203/codeql-bundle.tar.gz",
|
||||||
|
sampleApiDetails,
|
||||||
|
tmpDir,
|
||||||
|
util.GitHubVariant.DOTCOM,
|
||||||
|
false,
|
||||||
|
SAMPLE_DEFAULT_CLI_VERSION,
|
||||||
|
getRunnerLogger(true),
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
t.is(result.toolsVersion, "0.0.0-20230203");
|
||||||
|
t.is(result.toolsSource, ToolsSource.Download);
|
||||||
|
t.true(Number.isInteger(result.toolsDownloadDurationMs));
|
||||||
|
|
||||||
|
const cachedVersions = toolcache.findAllVersions("CodeQL");
|
||||||
|
t.is(cachedVersions.length, 1);
|
||||||
|
t.is(cachedVersions[0], "0.0.0-20230203");
|
||||||
|
|
||||||
|
t.false(releasesApiMock.isDone());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test("getExtraOptions works for explicit paths", (t) => {
|
test("getExtraOptions works for explicit paths", (t) => {
|
||||||
t.deepEqual(codeql.getExtraOptions({}, ["foo"], []), []);
|
t.deepEqual(codeql.getExtraOptions({}, ["foo"], []), []);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue