|
1 | 1 | import { once } from "events"; |
2 | 2 | import * as fs from "fs"; |
| 3 | +import { ClientRequest, IncomingMessage } from "http"; |
3 | 4 | import * as path from "path"; |
4 | 5 |
|
| 6 | +import * as core from "@actions/core"; |
5 | 7 | import * as toolcache from "@actions/tool-cache"; |
6 | 8 | import test from "ava"; |
| 9 | +import { https } from "follow-redirects"; |
7 | 10 | import nock from "nock"; |
8 | 11 | import * as sinon from "sinon"; |
9 | 12 |
|
@@ -158,6 +161,48 @@ test.serial( |
158 | 161 | }, |
159 | 162 | ); |
160 | 163 |
|
| 164 | +test.serial( |
| 165 | + "downloadAndExtract omits an unknown HTTP status from the error message", |
| 166 | + async (t) => { |
| 167 | + await withTmpDir(async (tmpDir) => { |
| 168 | + sinon.stub(process, "platform").value("linux"); |
| 169 | + const archivePath = path.join(tmpDir, "codeql-bundle.tar.zst"); |
| 170 | + const destination = path.join(tmpDir, "codeql"); |
| 171 | + const response = sinon.createStubInstance(IncomingMessage); |
| 172 | + response.statusCode = undefined; |
| 173 | + sinon |
| 174 | + .stub(https, "get") |
| 175 | + .callsArgWith(2, response) |
| 176 | + .returns(sinon.createStubInstance(ClientRequest)); |
| 177 | + const warning = sinon.stub(core, "warning"); |
| 178 | + const downloadTool = sinon |
| 179 | + .stub(toolcache, "downloadTool") |
| 180 | + .resolves(archivePath); |
| 181 | + const extract = sinon.stub(tar, "extract").resolves(destination); |
| 182 | + const extractTarZst = sinon.stub(tar, "extractTarZst").resolves(); |
| 183 | + |
| 184 | + await downloadAndExtract( |
| 185 | + "https://example.com/codeql-bundle.tar.zst", |
| 186 | + "zstd", |
| 187 | + destination, |
| 188 | + undefined, |
| 189 | + {}, |
| 190 | + { type: "gnu", version: "1.34" }, |
| 191 | + getRunnerLogger(true), |
| 192 | + ); |
| 193 | + |
| 194 | + t.is( |
| 195 | + warning.firstCall.args[0], |
| 196 | + "Failed to download and extract CodeQL bundle using streaming with error: Failed to download CodeQL bundle from https://example.com/codeql-bundle.tar.zst.", |
| 197 | + ); |
| 198 | + t.true(response.resume.calledOnce); |
| 199 | + t.false(extractTarZst.called); |
| 200 | + t.true(downloadTool.calledOnce); |
| 201 | + t.true(extract.calledOnce); |
| 202 | + }); |
| 203 | + }, |
| 204 | +); |
| 205 | + |
161 | 206 | test.serial( |
162 | 207 | "downloadAndExtract reports only the total duration when streaming extraction", |
163 | 208 | async (t) => { |
|
0 commit comments