1
1
using System . Text ;
2
2
using System . Text . Json ;
3
+ using System . Text . Json . Serialization ;
3
4
4
5
using NuGetUpdater . Core ;
5
6
using NuGetUpdater . Core . Discover ;
@@ -25,6 +26,8 @@ public async Task PathWithSpaces(bool useDirectDiscovery)
25
26
await RunAsync ( path =>
26
27
[
27
28
"discover" ,
29
+ "--job-id" ,
30
+ "TEST-JOB-ID" ,
28
31
"--job-path" ,
29
32
Path . Combine ( path , "job.json" ) ,
30
33
"--repo-root" ,
@@ -83,6 +86,8 @@ public async Task WithSolution(bool useDirectDiscovery)
83
86
await RunAsync ( path =>
84
87
[
85
88
"discover" ,
89
+ "--job-id" ,
90
+ "TEST-JOB-ID" ,
86
91
"--job-path" ,
87
92
Path . Combine ( path , "job.json" ) ,
88
93
"--repo-root" ,
@@ -178,6 +183,8 @@ public async Task WithProject(bool useDirectDiscovery)
178
183
await RunAsync ( path =>
179
184
[
180
185
"discover" ,
186
+ "--job-id" ,
187
+ "TEST-JOB-ID" ,
181
188
"--job-path" ,
182
189
Path . Combine ( path , "job.json" ) ,
183
190
"--repo-root" ,
@@ -251,6 +258,8 @@ public async Task WithDirectory(bool useDirectDiscovery)
251
258
await RunAsync ( path =>
252
259
[
253
260
"discover" ,
261
+ "--job-id" ,
262
+ "TEST-JOB-ID" ,
254
263
"--job-path" ,
255
264
Path . Combine ( path , "job.json" ) ,
256
265
"--repo-root" ,
@@ -321,6 +330,8 @@ public async Task WithDuplicateDependenciesOfDifferentTypes()
321
330
await RunAsync ( path =>
322
331
[
323
332
"discover" ,
333
+ "--job-id" ,
334
+ "TEST-JOB-ID" ,
324
335
"--job-path" ,
325
336
Path . Combine ( path , "job.json" ) ,
326
337
"--repo-root" ,
@@ -398,6 +409,8 @@ public async Task JobFileParseErrorIsReported_InvalidJson()
398
409
await RunAsync ( path =>
399
410
[
400
411
"discover" ,
412
+ "--job-id" ,
413
+ "TEST-JOB-ID" ,
401
414
"--job-path" ,
402
415
jobFilePath ,
403
416
"--repo-root" ,
@@ -412,8 +425,7 @@ await RunAsync(path =>
412
425
{
413
426
Path = "/" ,
414
427
Projects = [ ] ,
415
- ErrorType = ErrorType . Unknown ,
416
- ErrorDetailsPattern = "JsonException" ,
428
+ ErrorRegex = "Error deserializing job file contents" ,
417
429
}
418
430
) ;
419
431
}
@@ -445,6 +457,8 @@ await File.WriteAllTextAsync(jobFilePath, """
445
457
await RunAsync ( path =>
446
458
[
447
459
"discover" ,
460
+ "--job-id" ,
461
+ "TEST-JOB-ID" ,
448
462
"--job-path" ,
449
463
jobFilePath ,
450
464
"--repo-root" ,
@@ -459,8 +473,7 @@ await RunAsync(path =>
459
473
{
460
474
Path = "/" ,
461
475
Projects = [ ] ,
462
- ErrorType = ErrorType . BadRequirement ,
463
- ErrorDetailsPattern = "not a valid requirement" ,
476
+ Error = new Core . Run . ApiModel . BadRequirement ( "not a valid requirement" ) ,
464
477
}
465
478
) ;
466
479
}
@@ -497,7 +510,7 @@ private static async Task RunAsync(
497
510
switch ( args [ i ] )
498
511
{
499
512
case "--job-path" :
500
- var experimentsResult = await ExperimentsManager . FromJobFileAsync ( args [ i + 1 ] ) ;
513
+ var experimentsResult = await ExperimentsManager . FromJobFileAsync ( "TEST-JOB-ID" , args [ i + 1 ] ) ;
501
514
experimentsManager = experimentsResult . ExperimentsManager ;
502
515
break ;
503
516
case "--output" :
@@ -520,11 +533,38 @@ private static async Task RunAsync(
520
533
521
534
resultPath ??= Path . Join ( path , DiscoveryWorker . DiscoveryResultFileName ) ;
522
535
var resultJson = await File . ReadAllTextAsync ( resultPath ) ;
523
- var resultObject = JsonSerializer . Deserialize < WorkspaceDiscoveryResult > ( resultJson , DiscoveryWorker . SerializerOptions ) ;
536
+ var serializerOptions = new JsonSerializerOptions ( )
537
+ {
538
+ Converters = { new TestJobErrorBaseConverter ( ) }
539
+ } ;
540
+ foreach ( var converter in DiscoveryWorker . SerializerOptions . Converters )
541
+ {
542
+ serializerOptions . Converters . Add ( converter ) ;
543
+ }
544
+ var resultObject = JsonSerializer . Deserialize < WorkspaceDiscoveryResult > ( resultJson , serializerOptions ) ;
524
545
return resultObject ! ;
525
546
} ) ;
526
547
527
548
ValidateWorkspaceResult ( expectedResult , actualResult , experimentsManager ) ;
528
549
}
550
+
551
+ private class TestJobErrorBaseConverter : JsonConverter < Core . Run . ApiModel . JobErrorBase >
552
+ {
553
+ public override Core . Run . ApiModel . JobErrorBase ? Read ( ref Utf8JsonReader reader , Type typeToConvert , JsonSerializerOptions options )
554
+ {
555
+ var dict = JsonSerializer . Deserialize < Dictionary < string , JsonElement > > ( ref reader , options ) ! ;
556
+ return dict [ "error-type" ] . GetString ( ) switch
557
+ {
558
+ "illformed_requirement" => new Core . Run . ApiModel . BadRequirement ( dict [ "error-details" ] . GetProperty ( "message" ) . GetString ( ) ! ) ,
559
+ "unknown_error" => new Core . Run . ApiModel . UnknownError ( new Exception ( "Error deserializing job file contents" ) , "TEST-JOB-ID" ) ,
560
+ _ => throw new NotImplementedException ( $ "Unknown error type: { dict [ "error-type" ] } ") ,
561
+ } ;
562
+ }
563
+
564
+ public override void Write ( Utf8JsonWriter writer , Core . Run . ApiModel . JobErrorBase value , JsonSerializerOptions options )
565
+ {
566
+ throw new NotImplementedException ( ) ;
567
+ }
568
+ }
529
569
}
530
570
}
0 commit comments