@@ -2,13 +2,18 @@ import test from "ava";
2
2
import * as sinon from "sinon" ;
3
3
4
4
import * as actionsUtil from "./actions-util" ;
5
+ import { Config } from "./config-utils" ;
5
6
import { EnvVar } from "./environment" ;
6
7
import { KnownLanguage } from "./languages" ;
7
8
import { getRunnerLogger } from "./logging" ;
9
+ import { ToolsSource } from "./setup-codeql" ;
8
10
import {
9
11
ActionName ,
12
+ createInitWithConfigStatusReport ,
10
13
createStatusReportBase ,
11
14
getActionsStatus ,
15
+ InitStatusReport ,
16
+ InitWithConfigStatusReport ,
12
17
} from "./status-report" ;
13
18
import {
14
19
setupTests ,
@@ -243,3 +248,103 @@ test("getActionStatus handling correctly various types of errors", (t) => {
243
248
"We still recognise a wrapped ConfigurationError as a user error" ,
244
249
) ;
245
250
} ) ;
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