Skip to content

Commit 6394750

Browse files
committed
Add test for sendFailedStatusReport
1 parent f1588cd commit 6394750

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

src/start-proxy.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as core from "@actions/core";
12
import * as toolcache from "@actions/tool-cache";
23
import test from "ava";
34
import sinon from "sinon";
@@ -8,6 +9,7 @@ import { KnownLanguage } from "./languages";
89
import { getRunnerLogger } from "./logging";
910
import * as startProxyExports from "./start-proxy";
1011
import { parseLanguage } from "./start-proxy";
12+
import * as statusReport from "./status-report";
1113
import {
1214
checkExpectedLogMessages,
1315
getRecordingLogger,
@@ -17,6 +19,51 @@ import {
1719

1820
setupTests(test);
1921

22+
test("sendFailedStatusReport - does not report arbitrary error messages", async (t) => {
23+
const loggedMessages = [];
24+
const logger = getRecordingLogger(loggedMessages);
25+
const error = new Error(startProxyExports.StartProxyErrorType.DownloadFailed);
26+
const now = new Date();
27+
28+
// Override core.setFailed to avoid it setting the program's exit code
29+
sinon.stub(core, "setFailed").returns();
30+
31+
const createStatusReportBase = sinon.stub(
32+
statusReport,
33+
"createStatusReportBase",
34+
);
35+
createStatusReportBase.resolves(undefined);
36+
37+
await startProxyExports.sendFailedStatusReport(logger, now, undefined, error);
38+
39+
// Check that the stub has been called exactly once, with the expected arguments,
40+
// but not with the message from the error.
41+
t.assert(createStatusReportBase.calledOnce);
42+
t.assert(
43+
createStatusReportBase.calledWith(
44+
statusReport.ActionName.StartProxy,
45+
"failure",
46+
now,
47+
sinon.match.any,
48+
sinon.match.any,
49+
sinon.match.any,
50+
),
51+
"createStatusReportBase wasn't called with the expected arguments",
52+
);
53+
t.false(
54+
createStatusReportBase.calledWith(
55+
statusReport.ActionName.StartProxy,
56+
"failure",
57+
now,
58+
sinon.match.any,
59+
sinon.match.any,
60+
sinon.match.any,
61+
sinon.match((msg: string) => msg.includes(error.message)),
62+
),
63+
"createStatusReportBase was called with the error message",
64+
);
65+
});
66+
2067
const toEncodedJSON = (data: any) =>
2168
Buffer.from(JSON.stringify(data)).toString("base64");
2269

0 commit comments

Comments
 (0)