@@ -322,7 +322,11 @@ func httpCall(t *testing.T, httpMethod string, url string, contentType string, a
322
322
var bytes []byte
323
323
324
324
if response != nil {
325
- defer response .Body .Close ()
325
+ defer func () {
326
+ if err := response .Body .Close (); err != nil {
327
+ t .Errorf ("failed to close response body while calling %s" , url )
328
+ }
329
+ }()
326
330
327
331
statusCode = response .StatusCode
328
332
@@ -535,10 +539,18 @@ func checkCopy(t *testing.T, s3proxyHost string, sourceBucket string, sourceKey
535
539
require .Empty (t , message )
536
540
537
541
sourceFile := checkUpload (t , s3proxyHost , sourceBucket + sourceKey , "" )
538
- defer os .Remove (sourceFile .Name ())
542
+ defer func () {
543
+ if err := os .Remove (sourceFile .Name ()); err != nil {
544
+ log .Errorf ("failed to remove source file %s: %v" , sourceFile .Name (), err )
545
+ }
546
+ }()
539
547
540
548
destinationFile := checkDownload (t , s3proxyHost , destBucket + destKey , http .StatusOK , "" )
541
- defer os .Remove (destinationFile .Name ())
549
+ defer func () {
550
+ if err := os .Remove (destinationFile .Name ()); err != nil {
551
+ log .Errorf ("failed to remove destination file %s: %v" , destinationFile .Name (), err )
552
+ }
553
+ }()
542
554
543
555
// Verify the files are the same
544
556
require .True (t , verifyFileCheckSumEquality (t , sourceFile , destinationFile ))
@@ -563,7 +575,11 @@ func checkBatchDelete(t *testing.T, s3proxyHost string, bucket string, keys []st
563
575
// Last check, try to download again the file
564
576
// should return 404 because the file has been deleted
565
577
file := checkDownload (t , s3proxyHost , bucket + key , http .StatusNotFound , "" )
566
- defer os .Remove (file .Name ())
578
+ defer func () {
579
+ if err := os .Remove (file .Name ()); err != nil {
580
+ log .Errorf ("failed to remove downloaded file %s: %v" , file .Name (), err )
581
+ }
582
+ }()
567
583
}
568
584
}
569
585
@@ -583,22 +599,38 @@ func RunSimpleScenarioForS3proxy(t *testing.T, s3proxyHost string) {
583
599
584
600
// UPLOAD a temporary file to the s3 backend
585
601
uploadedFile := checkUpload (t , s3proxyHost , fullKey , "" )
586
- defer os .Remove (uploadedFile .Name ())
602
+ defer func () {
603
+ if err := os .Remove (uploadedFile .Name ()); err != nil {
604
+ log .Errorf ("failed to remove uploaded file %s: %v" , uploadedFile .Name (), err )
605
+ }
606
+ }()
587
607
588
608
// DOWNLOAD the file previously uploaded
589
609
downloadedFile := checkDownload (t , s3proxyHost , fullKey , http .StatusOK , "" )
590
- defer os .Remove (downloadedFile .Name ())
610
+ defer func () {
611
+ if err := os .Remove (downloadedFile .Name ()); err != nil {
612
+ log .Errorf ("failed to remove downloaded file %s: %v" , downloadedFile .Name (), err )
613
+ }
614
+ }()
591
615
592
616
// Verify the files are the same
593
617
require .True (t , verifyFileCheckSumEquality (t , uploadedFile , downloadedFile ))
594
618
595
619
// UPLOAD a temporary file to the s3 backend with expiration
596
620
getUploadFileWithExpiration := checkUpload (t , s3proxyHost , fullKey , "25m" )
597
- defer os .Remove (getUploadFileWithExpiration .Name ())
621
+ defer func () {
622
+ if err := os .Remove (getUploadFileWithExpiration .Name ()); err != nil {
623
+ log .Errorf ("failed to remove uploaded file with expiration %s: %v" , getUploadFileWithExpiration .Name (), err )
624
+ }
625
+ }()
598
626
599
627
// DOWNLOAD the file previously uploaded with expiration
600
628
getDownloadFileWithExpiration := checkDownload (t , s3proxyHost , fullKey , http .StatusOK , "25m" )
601
- defer os .Remove (getDownloadFileWithExpiration .Name ())
629
+ defer func () {
630
+ if err := os .Remove (getDownloadFileWithExpiration .Name ()); err != nil {
631
+ log .Errorf ("failed to remove downloaded file with expiration %s: %v" , getDownloadFileWithExpiration .Name (), err )
632
+ }
633
+ }()
602
634
603
635
// Verify the expiration param is taken into account
604
636
require .True (t , verifyFileCheckSumEquality (t , getUploadFileWithExpiration , getDownloadFileWithExpiration ))
@@ -607,7 +639,11 @@ func RunSimpleScenarioForS3proxy(t *testing.T, s3proxyHost string) {
607
639
checkCopy (t , s3proxyHost , bucket , key , bucket , key + "2" )
608
640
609
641
copiedFile := checkDownload (t , s3proxyHost , fullKey + "2" , http .StatusOK , "" )
610
- defer os .Remove (copiedFile .Name ())
642
+ defer func () {
643
+ if err := os .Remove (copiedFile .Name ()); err != nil {
644
+ log .Errorf ("failed to remove copied file %s: %v" , copiedFile .Name (), err )
645
+ }
646
+ }()
611
647
612
648
// DELETE object
613
649
checkDelete (t , s3proxyHost , fullKey + "2" )
0 commit comments