@@ -383,6 +383,103 @@ fn chunk_upload_multiple_files() {
383
383
. run_and_assert ( AssertCommand :: Success ) ;
384
384
}
385
385
386
+ #[ test]
387
+ /// This test verifies a correct chunk upload of multiple debug files,
388
+ /// where one of the files is already uploaded.
389
+ /// Only the missing files should be uploaded.
390
+ fn chunk_upload_multiple_files_only_some ( ) {
391
+ let expected_chunk_body = fs:: read (
392
+ "tests/integration/_expected_requests/debug_files/upload/chunk_upload_multiple_files_only_some.bin" ,
393
+ )
394
+ . expect ( "expected chunk body file should be present" ) ;
395
+
396
+ /// This is the boundary used in the expected request file.
397
+ /// It was randomly generated when the expected request was recorded.
398
+ const EXPECTED_REQUEST_BOUNDARY : & str = "------------------------mfIgsRj6pG8q8GGnJIShDh" ;
399
+
400
+ let is_first_assemble_call = AtomicBool :: new ( true ) ;
401
+ TestManager :: new ( )
402
+ . mock_endpoint (
403
+ MockEndpointBuilder :: new ( "GET" , "/api/0/organizations/wat-org/chunk-upload/" )
404
+ . with_response_file ( "debug_files/get-chunk-upload.json" ) ,
405
+ )
406
+ . mock_endpoint (
407
+ MockEndpointBuilder :: new ( "POST" , "/api/0/organizations/wat-org/chunk-upload/" )
408
+ . with_response_fn ( move |request| {
409
+ let boundary = chunk_upload:: boundary_from_request ( request)
410
+ . expect ( "content-type header should be a valid multipart/form-data header" ) ;
411
+
412
+ let body = request. body ( ) . expect ( "body should be readable" ) ;
413
+ let chunks = chunk_upload:: split_chunk_body ( body, boundary)
414
+ . expect ( "body should be a valid multipart/form-data body" ) ;
415
+
416
+ let expected_chunks = chunk_upload:: split_chunk_body (
417
+ & expected_chunk_body,
418
+ EXPECTED_REQUEST_BOUNDARY ,
419
+ )
420
+ . expect ( "expected chunk body is a valid multipart/form-data body" ) ;
421
+
422
+ // Using assert! because in case of failure, the output with assert_eq!
423
+ // is too long to be useful.
424
+ assert ! (
425
+ chunks == expected_chunks,
426
+ "Uploaded chunks differ from the expected chunks"
427
+ ) ;
428
+
429
+ vec ! [ ]
430
+ } ) ,
431
+ )
432
+ . mock_endpoint (
433
+ MockEndpointBuilder :: new (
434
+ "POST" ,
435
+ "/api/0/projects/wat-org/wat-project/files/difs/assemble/" ,
436
+ )
437
+ . with_header_matcher ( "content-type" , "application/json" )
438
+ . with_response_fn ( move |_| {
439
+ if is_first_assemble_call. swap ( false , Ordering :: Relaxed ) {
440
+ r#"{
441
+ "6e217f035ed538d4d6c14129baad5cb52e680e74": {
442
+ "state": "ok",
443
+ "missingChunks": []
444
+ },
445
+ "500848b7815119669a292f2ae1f44af11d7aa2d3": {
446
+ "state": "not_found",
447
+ "missingChunks": ["500848b7815119669a292f2ae1f44af11d7aa2d3"]
448
+ },
449
+ "fc27d95861d56fe16a2b66150e31652b76e8c678": {
450
+ "state": "not_found",
451
+ "missingChunks": ["fc27d95861d56fe16a2b66150e31652b76e8c678"]
452
+ }
453
+ }"#
454
+ } else {
455
+ r#"{
456
+ "6e217f035ed538d4d6c14129baad5cb52e680e74": {
457
+ "state": "ok",
458
+ "missingChunks": []
459
+ },
460
+ "500848b7815119669a292f2ae1f44af11d7aa2d3": {
461
+ "state": "created",
462
+ "missingChunks": []
463
+ },
464
+ "fc27d95861d56fe16a2b66150e31652b76e8c678": {
465
+ "state": "created",
466
+ "missingChunks": []
467
+ }
468
+ }"#
469
+ }
470
+ . into ( )
471
+ } )
472
+ . expect ( 2 ) ,
473
+ )
474
+ . assert_cmd ( vec ! [
475
+ "debug-files" ,
476
+ "upload" ,
477
+ "tests/integration/_fixtures/debug_files/upload/chunk_upload_multiple_files" ,
478
+ ] )
479
+ . with_default_token ( )
480
+ . run_and_assert ( AssertCommand :: Success ) ;
481
+ }
482
+
386
483
#[ test]
387
484
/// This test verifies a correct chunk upload of multiple debug files
388
485
/// with a small chunk size (2048 bytes).
0 commit comments