mirror of
https://github.com/github/codeql-action.git
synced 2026-10-03 17:41:28 +00:00
Strengthen download status report tests
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -156,6 +156,7 @@ test.serial(
|
||||
t.assert(toolcache.find("CodeQL", `0.0.0-${version}`));
|
||||
t.is(result.toolsVersion, `0.0.0-${version}`);
|
||||
t.is(result.toolsSource, ToolsSource.Download);
|
||||
assertDownloadDurationInteger(t, result.toolsDownloadStatusReport);
|
||||
}
|
||||
|
||||
t.is(toolcache.findAllVersions("CodeQL").length, 2);
|
||||
@@ -191,9 +192,7 @@ test.serial(
|
||||
t.assert(toolcache.find("CodeQL", `2.15.0`));
|
||||
t.is(result.toolsVersion, `2.15.0`);
|
||||
t.is(result.toolsSource, ToolsSource.Download);
|
||||
if (result.toolsDownloadStatusReport) {
|
||||
assertDownloadDurationInteger(t, result.toolsDownloadStatusReport);
|
||||
}
|
||||
assertDownloadDurationInteger(t, result.toolsDownloadStatusReport);
|
||||
});
|
||||
},
|
||||
);
|
||||
@@ -230,9 +229,7 @@ test.serial(
|
||||
t.assert(toolcache.find("CodeQL", "0.0.0-20200610"));
|
||||
t.deepEqual(result.toolsVersion, "0.0.0-20200610");
|
||||
t.is(result.toolsSource, ToolsSource.Download);
|
||||
if (result.toolsDownloadStatusReport) {
|
||||
assertDownloadDurationInteger(t, result.toolsDownloadStatusReport);
|
||||
}
|
||||
assertDownloadDurationInteger(t, result.toolsDownloadStatusReport);
|
||||
});
|
||||
},
|
||||
);
|
||||
@@ -282,11 +279,7 @@ for (const {
|
||||
t.assert(toolcache.find("CodeQL", expectedToolcacheVersion));
|
||||
t.deepEqual(result.toolsVersion, expectedToolcacheVersion);
|
||||
t.is(result.toolsSource, ToolsSource.Download);
|
||||
t.assert(
|
||||
Number.isInteger(
|
||||
result.toolsDownloadStatusReport?.downloadDurationMs,
|
||||
),
|
||||
);
|
||||
assertDownloadDurationInteger(t, result.toolsDownloadStatusReport);
|
||||
});
|
||||
},
|
||||
);
|
||||
@@ -417,9 +410,7 @@ test.serial(
|
||||
);
|
||||
t.deepEqual(result.toolsVersion, defaults.cliVersion);
|
||||
t.is(result.toolsSource, ToolsSource.Download);
|
||||
if (result.toolsDownloadStatusReport) {
|
||||
assertDownloadDurationInteger(t, result.toolsDownloadStatusReport);
|
||||
}
|
||||
t.truthy(result.toolsDownloadStatusReport);
|
||||
|
||||
const cachedVersions = toolcache.findAllVersions("CodeQL");
|
||||
t.is(cachedVersions.length, 2);
|
||||
@@ -458,9 +449,7 @@ test.serial(
|
||||
);
|
||||
t.deepEqual(result.toolsVersion, defaults.cliVersion);
|
||||
t.is(result.toolsSource, ToolsSource.Download);
|
||||
if (result.toolsDownloadStatusReport) {
|
||||
assertDownloadDurationInteger(t, result.toolsDownloadStatusReport);
|
||||
}
|
||||
t.truthy(result.toolsDownloadStatusReport);
|
||||
|
||||
const cachedVersions = toolcache.findAllVersions("CodeQL");
|
||||
t.is(cachedVersions.length, 2);
|
||||
@@ -502,9 +491,7 @@ test.serial(
|
||||
|
||||
t.is(result.toolsVersion, "0.0.0-20230203");
|
||||
t.is(result.toolsSource, ToolsSource.Download);
|
||||
if (result.toolsDownloadStatusReport) {
|
||||
assertDownloadDurationInteger(t, result.toolsDownloadStatusReport);
|
||||
}
|
||||
assertDownloadDurationInteger(t, result.toolsDownloadStatusReport);
|
||||
|
||||
const cachedVersions = toolcache.findAllVersions("CodeQL");
|
||||
t.is(cachedVersions.length, 1);
|
||||
@@ -517,11 +504,9 @@ test.serial(
|
||||
|
||||
function assertDownloadDurationInteger(
|
||||
t: ExecutionContext<unknown>,
|
||||
statusReport: ToolsDownloadStatusReport,
|
||||
statusReport: ToolsDownloadStatusReport | undefined,
|
||||
) {
|
||||
if (statusReport.downloadDurationMs !== undefined) {
|
||||
t.assert(Number.isInteger(statusReport.downloadDurationMs));
|
||||
}
|
||||
t.assert(Number.isInteger(statusReport?.downloadDurationMs));
|
||||
}
|
||||
|
||||
test.serial("getExtraOptions works for explicit paths", (t) => {
|
||||
|
||||
78
src/tools-download.test.ts
Normal file
78
src/tools-download.test.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
import { once } from "events";
|
||||
import * as path from "path";
|
||||
|
||||
import * as toolcache from "@actions/tool-cache";
|
||||
import test from "ava";
|
||||
import nock from "nock";
|
||||
import * as sinon from "sinon";
|
||||
|
||||
import { getRunnerLogger } from "./logging";
|
||||
import * as tar from "./tar";
|
||||
import { setupTests } from "./testing-utils";
|
||||
import { downloadAndExtract } from "./tools-download";
|
||||
import { withTmpDir } from "./util";
|
||||
|
||||
setupTests(test);
|
||||
|
||||
test.serial(
|
||||
"downloadAndExtract reports the duration when downloading before extracting",
|
||||
async (t) => {
|
||||
await withTmpDir(async (tmpDir) => {
|
||||
const archivePath = path.join(tmpDir, "codeql-bundle.tar.gz");
|
||||
const destination = path.join(tmpDir, "codeql");
|
||||
sinon.stub(toolcache, "downloadTool").resolves(archivePath);
|
||||
sinon.stub(tar, "extract").resolves(destination);
|
||||
|
||||
const statusReport = await downloadAndExtract(
|
||||
"https://example.com/codeql-bundle.tar.gz",
|
||||
"gzip",
|
||||
destination,
|
||||
undefined,
|
||||
{},
|
||||
undefined,
|
||||
getRunnerLogger(true),
|
||||
);
|
||||
|
||||
t.assert(Number.isInteger(statusReport.downloadDurationMs));
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
test.serial(
|
||||
"downloadAndExtract omits the download duration when streaming extraction",
|
||||
async (t) => {
|
||||
await withTmpDir(async (tmpDir) => {
|
||||
sinon.stub(process, "platform").value("linux");
|
||||
const downloadTool = sinon.stub(toolcache, "downloadTool");
|
||||
const extractTarZst = sinon
|
||||
.stub(tar, "extractTarZst")
|
||||
.callsFake(async (archive) => {
|
||||
if (typeof archive === "string") {
|
||||
t.fail("Expected the Zstandard archive to be streamed.");
|
||||
return;
|
||||
}
|
||||
const end = once(archive, "end");
|
||||
archive.resume();
|
||||
await end;
|
||||
});
|
||||
const request = nock("https://example.com")
|
||||
.get("/codeql-bundle.tar.zst")
|
||||
.reply(200, "archive");
|
||||
|
||||
const statusReport = await downloadAndExtract(
|
||||
"https://example.com/codeql-bundle.tar.zst",
|
||||
"zstd",
|
||||
path.join(tmpDir, "codeql"),
|
||||
undefined,
|
||||
{},
|
||||
{ type: "gnu", version: "1.34" },
|
||||
getRunnerLogger(true),
|
||||
);
|
||||
|
||||
t.deepEqual(statusReport, {});
|
||||
t.false(downloadTool.called);
|
||||
t.true(extractTarZst.calledOnce);
|
||||
t.true(request.isDone());
|
||||
});
|
||||
},
|
||||
);
|
||||
Reference in New Issue
Block a user