@@ -31,6 +31,7 @@ import (
31
31
32
32
"github.com/docker/docker/api/types"
33
33
"github.com/docker/docker/api/types/container"
34
+ imagetypes "github.com/docker/docker/api/types/image"
34
35
"github.com/docker/docker/client"
35
36
"github.com/docker/docker/pkg/stdcopy"
36
37
"github.com/docker/go-connections/nat"
@@ -82,11 +83,11 @@ type backupTarget struct {
82
83
}
83
84
84
85
type testOptions struct {
85
- compact bool
86
+ compact bool //nolint:unused // used in the future
86
87
targets []string
87
88
dc * dockerContext
88
89
base string
89
- prePost bool
90
+ prePost bool //nolint:unused // used in the future
90
91
backupData []byte
91
92
mysql containerPort
92
93
smb containerPort
@@ -333,8 +334,8 @@ func (d *dockerContext) makeSMB(smbImage string) error {
333
334
if err != nil {
334
335
return fmt .Errorf ("failed to build smb image: %w" , err )
335
336
}
336
- io .Copy (os .Stdout , resp .Body )
337
- resp .Body .Close ()
337
+ _ , _ = io .Copy (os .Stdout , resp .Body )
338
+ _ = resp .Body .Close ()
338
339
339
340
return nil
340
341
}
@@ -440,7 +441,9 @@ DELIMITER ;
440
441
if err != nil {
441
442
return err
442
443
}
443
- defer fCompact .Close ()
444
+ defer func () {
445
+ _ = fCompact .Close ()
446
+ }()
444
447
445
448
_ , _ = stdcopy .StdCopy (fCompact , & bufe , attachResp .Reader )
446
449
@@ -461,12 +464,15 @@ DELIMITER ;
461
464
if err != nil {
462
465
return err
463
466
}
464
- defer f .Close ()
467
+ defer func () {
468
+ _ = f .Close ()
469
+ }()
465
470
466
471
_ , _ = stdcopy .StdCopy (f , & bufe , attachResp .Reader )
467
472
return err
468
473
}
469
474
475
+ //nolint:unused // useful in the future
470
476
func (d * dockerContext ) logContainers (cids ... string ) error {
471
477
ctx := context .Background ()
472
478
for _ , cid := range cids {
@@ -478,7 +484,9 @@ func (d *dockerContext) logContainers(cids ...string) error {
478
484
if err != nil {
479
485
return fmt .Errorf ("failed to get logs for container %s: %w" , cid , err )
480
486
}
481
- defer logs .Close ()
487
+ defer func () {
488
+ _ = logs .Close ()
489
+ }()
482
490
483
491
if _ , err := io .Copy (os .Stdout , logs ); err != nil {
484
492
return fmt .Errorf ("failed to stream logs for container %s: %w" , cid , err )
@@ -558,12 +566,12 @@ log_queries_not_using_indexes = 1
558
566
return mysql , smb , s3url , s3backend , fmt .Errorf ("failed to create mysql log directory: %v" , err )
559
567
}
560
568
// ensure we have mysql image
561
- resp , err := dc .cli .ImagePull (context .Background (), mysqlImage , types. ImagePullOptions {})
569
+ resp , err := dc .cli .ImagePull (context .Background (), mysqlImage , imagetypes. PullOptions {})
562
570
if err != nil {
563
571
return mysql , smb , s3url , s3backend , fmt .Errorf ("failed to pull mysql image: %v" , err )
564
572
}
565
- io .Copy (os .Stdout , resp )
566
- resp .Close ()
573
+ _ , _ = io .Copy (os .Stdout , resp )
574
+ _ = resp .Close ()
567
575
mysqlCID , mysqlPort , err := dc .startContainer (mysqlImage , "mysql" , "3306/tcp" , []string {fmt .Sprintf ("%s:/etc/mysql/conf.d/log.conf:ro" , confFile ), fmt .Sprintf ("%s:/var/log/mysql" , logDir )}, nil , []string {
568
576
fmt .Sprintf ("MYSQL_ROOT_PASSWORD=%s" , mysqlRootPass ),
569
577
"MYSQL_DATABASE=tester" ,
@@ -592,8 +600,7 @@ func backupTargetsToStorage(targets []backupTarget, base, s3 string) ([]storage.
592
600
var targetVals []storage.Storage
593
601
// all targets should have the same sequence, with varying subsequence, so take any one
594
602
for _ , tgt := range targets {
595
- tg := tgt .String ()
596
- tg = tgt .WithPrefix (base )
603
+ tg := tgt .WithPrefix (base )
597
604
localPath := tgt .LocalPath ()
598
605
if err := os .MkdirAll (localPath , 0o755 ); err != nil {
599
606
return nil , fmt .Errorf ("failed to create local path %s: %v" , localPath , err )
@@ -751,13 +758,13 @@ func checkDumpTest(t *testing.T, base string, expected []byte, s3backend gofakes
751
758
if _ , err := os .Stat (postBackupOutFile ); err != nil {
752
759
t .Errorf ("%s script didn't run, output file doesn't exist" , msg )
753
760
}
754
- os .RemoveAll (postBackupOutFile )
761
+ _ = os .RemoveAll (postBackupOutFile )
755
762
756
763
msg = fmt .Sprintf ("%s %s pre-backup" , id , target .String ())
757
764
if _ , err := os .Stat (preBackupOutFile ); err != nil {
758
765
t .Errorf ("%s script didn't run, output file doesn't exist" , msg )
759
766
}
760
- os .RemoveAll (preBackupOutFile )
767
+ _ = os .RemoveAll (preBackupOutFile )
761
768
}
762
769
p := target .Path ()
763
770
if p == "" {
@@ -803,8 +810,6 @@ func checkDumpTest(t *testing.T, base string, expected []byte, s3backend gofakes
803
810
// to each format
804
811
assert .Equal (t , expectedFiltered , string (b ), "%s tar contents do not match actual dump" , id )
805
812
}
806
-
807
- return
808
813
}
809
814
810
815
// gunzipUntarScanFilter is a helper function to extract the actual data from a backup
@@ -815,7 +820,9 @@ func gunzipUntarScanFilter(r io.Reader) (b []byte, err error) {
815
820
if err != nil {
816
821
return nil , err
817
822
}
818
- defer gr .Close ()
823
+ defer func () {
824
+ _ = gr .Close ()
825
+ }()
819
826
tr := tar .NewReader (gr )
820
827
if _ , err := tr .Next (); err != nil {
821
828
return nil , err
@@ -884,12 +891,12 @@ func populatePrePost(base string, targets []backupTarget) (err error) {
884
891
}
885
892
886
893
func startDatabase (dc * dockerContext , baseDir , image , name string ) (containerPort , error ) {
887
- resp , err := dc .cli .ImagePull (context .Background (), image , types. ImagePullOptions {})
894
+ resp , err := dc .cli .ImagePull (context .Background (), image , imagetypes. PullOptions {})
888
895
if err != nil {
889
896
return containerPort {}, fmt .Errorf ("failed to pull mysql image: %v" , err )
890
897
}
891
- io .Copy (os .Stdout , resp )
892
- resp .Close ()
898
+ _ , _ = io .Copy (os .Stdout , resp )
899
+ _ = resp .Close ()
893
900
894
901
// start the mysql container; configure it for lots of debug logging, in case we need it
895
902
mysqlConf := `
0 commit comments