Skip to content

Commit 920bba1

Browse files
committed
Add unit tests for createInitWithConfigStatusReport
1 parent 37ddb03 commit 920bba1

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

src/status-report.test.ts

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@ import test from "ava";
22
import * as sinon from "sinon";
33

44
import * as actionsUtil from "./actions-util";
5+
import { Config } from "./config-utils";
56
import { EnvVar } from "./environment";
67
import { KnownLanguage } from "./languages";
78
import { getRunnerLogger } from "./logging";
9+
import { ToolsSource } from "./setup-codeql";
810
import {
911
ActionName,
12+
createInitWithConfigStatusReport,
1013
createStatusReportBase,
1114
getActionsStatus,
15+
InitStatusReport,
16+
InitWithConfigStatusReport,
1217
} from "./status-report";
1318
import {
1419
setupTests,
@@ -243,3 +248,103 @@ test("getActionStatus handling correctly various types of errors", (t) => {
243248
"We still recognise a wrapped ConfigurationError as a user error",
244249
);
245250
});
251+
252+
const testCreateInitWithConfigStatusReport = test.macro({
253+
exec: async (
254+
t,
255+
_title: string,
256+
config: Config,
257+
expectedReportProperties: Partial<InitWithConfigStatusReport>,
258+
) => {
259+
await withTmpDir(async (tmpDir: string) => {
260+
setupEnvironmentAndStub(tmpDir);
261+
262+
const statusReportBase = await createStatusReportBase(
263+
ActionName.Init,
264+
"failure",
265+
new Date("May 19, 2023 05:19:00"),
266+
config,
267+
{ numAvailableBytes: 100, numTotalBytes: 500 },
268+
getRunnerLogger(false),
269+
"failure cause",
270+
"exception stack trace",
271+
);
272+
273+
if (t.truthy(statusReportBase)) {
274+
const initStatusReport: InitStatusReport = {
275+
...statusReportBase,
276+
tools_input: "",
277+
tools_resolved_version: "foo",
278+
tools_source: ToolsSource.Unknown,
279+
workflow_languages: "actions",
280+
};
281+
282+
const initWithConfigStatusReport =
283+
await createInitWithConfigStatusReport(
284+
config,
285+
initStatusReport,
286+
undefined,
287+
1024,
288+
undefined,
289+
);
290+
291+
if (t.truthy(initWithConfigStatusReport)) {
292+
t.like(initWithConfigStatusReport, expectedReportProperties);
293+
}
294+
}
295+
});
296+
},
297+
title: (_, title) => `createInitWithConfigStatusReport: ${title}`,
298+
});
299+
300+
test(
301+
testCreateInitWithConfigStatusReport,
302+
"returns a value",
303+
createTestConfig({
304+
buildMode: BuildMode.None,
305+
languages: [KnownLanguage.java, KnownLanguage.swift],
306+
}),
307+
{
308+
trap_cache_download_size_bytes: 1024,
309+
registries: "[]",
310+
query_filters: "[]",
311+
packs: "{}",
312+
},
313+
);
314+
315+
test(
316+
testCreateInitWithConfigStatusReport,
317+
"includes packs for a single language",
318+
createTestConfig({
319+
buildMode: BuildMode.None,
320+
languages: [KnownLanguage.java],
321+
computedConfig: {
322+
packs: ["foo", "bar"],
323+
},
324+
}),
325+
{
326+
registries: "[]",
327+
query_filters: "[]",
328+
packs: JSON.stringify({ java: ["foo", "bar"] }),
329+
},
330+
);
331+
332+
test(
333+
testCreateInitWithConfigStatusReport,
334+
"includes packs for multiple languages",
335+
createTestConfig({
336+
buildMode: BuildMode.None,
337+
languages: [KnownLanguage.java, KnownLanguage.swift],
338+
computedConfig: {
339+
packs: { java: ["java-foo", "java-bar"], swift: ["swift-bar"] },
340+
},
341+
}),
342+
{
343+
registries: "[]",
344+
query_filters: "[]",
345+
packs: JSON.stringify({
346+
java: ["java-foo", "java-bar"],
347+
swift: ["swift-bar"],
348+
}),
349+
},
350+
);

0 commit comments

Comments
 (0)