Skip to content

Commit 68ac091

Browse files
committed
fix lint issues
Signed-off-by: Avi Deitcher <avi@deitcher.net>
1 parent fa13a70 commit 68ac091

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

test/backup_test.go

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131

3232
"github.com/docker/docker/api/types"
3333
"github.com/docker/docker/api/types/container"
34+
imagetypes "github.com/docker/docker/api/types/image"
3435
"github.com/docker/docker/client"
3536
"github.com/docker/docker/pkg/stdcopy"
3637
"github.com/docker/go-connections/nat"
@@ -82,11 +83,11 @@ type backupTarget struct {
8283
}
8384

8485
type testOptions struct {
85-
compact bool
86+
compact bool //nolint:unused // used in the future
8687
targets []string
8788
dc *dockerContext
8889
base string
89-
prePost bool
90+
prePost bool //nolint:unused // used in the future
9091
backupData []byte
9192
mysql containerPort
9293
smb containerPort
@@ -333,8 +334,8 @@ func (d *dockerContext) makeSMB(smbImage string) error {
333334
if err != nil {
334335
return fmt.Errorf("failed to build smb image: %w", err)
335336
}
336-
io.Copy(os.Stdout, resp.Body)
337-
resp.Body.Close()
337+
_, _ = io.Copy(os.Stdout, resp.Body)
338+
_ = resp.Body.Close()
338339

339340
return nil
340341
}
@@ -440,7 +441,9 @@ DELIMITER ;
440441
if err != nil {
441442
return err
442443
}
443-
defer fCompact.Close()
444+
defer func() {
445+
_ = fCompact.Close()
446+
}()
444447

445448
_, _ = stdcopy.StdCopy(fCompact, &bufe, attachResp.Reader)
446449

@@ -461,12 +464,15 @@ DELIMITER ;
461464
if err != nil {
462465
return err
463466
}
464-
defer f.Close()
467+
defer func() {
468+
_ = f.Close()
469+
}()
465470

466471
_, _ = stdcopy.StdCopy(f, &bufe, attachResp.Reader)
467472
return err
468473
}
469474

475+
//nolint:unused // useful in the future
470476
func (d *dockerContext) logContainers(cids ...string) error {
471477
ctx := context.Background()
472478
for _, cid := range cids {
@@ -478,7 +484,9 @@ func (d *dockerContext) logContainers(cids ...string) error {
478484
if err != nil {
479485
return fmt.Errorf("failed to get logs for container %s: %w", cid, err)
480486
}
481-
defer logs.Close()
487+
defer func() {
488+
_ = logs.Close()
489+
}()
482490

483491
if _, err := io.Copy(os.Stdout, logs); err != nil {
484492
return fmt.Errorf("failed to stream logs for container %s: %w", cid, err)
@@ -558,12 +566,12 @@ log_queries_not_using_indexes = 1
558566
return mysql, smb, s3url, s3backend, fmt.Errorf("failed to create mysql log directory: %v", err)
559567
}
560568
// 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{})
562570
if err != nil {
563571
return mysql, smb, s3url, s3backend, fmt.Errorf("failed to pull mysql image: %v", err)
564572
}
565-
io.Copy(os.Stdout, resp)
566-
resp.Close()
573+
_, _ = io.Copy(os.Stdout, resp)
574+
_ = resp.Close()
567575
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{
568576
fmt.Sprintf("MYSQL_ROOT_PASSWORD=%s", mysqlRootPass),
569577
"MYSQL_DATABASE=tester",
@@ -592,8 +600,7 @@ func backupTargetsToStorage(targets []backupTarget, base, s3 string) ([]storage.
592600
var targetVals []storage.Storage
593601
// all targets should have the same sequence, with varying subsequence, so take any one
594602
for _, tgt := range targets {
595-
tg := tgt.String()
596-
tg = tgt.WithPrefix(base)
603+
tg := tgt.WithPrefix(base)
597604
localPath := tgt.LocalPath()
598605
if err := os.MkdirAll(localPath, 0o755); err != nil {
599606
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
751758
if _, err := os.Stat(postBackupOutFile); err != nil {
752759
t.Errorf("%s script didn't run, output file doesn't exist", msg)
753760
}
754-
os.RemoveAll(postBackupOutFile)
761+
_ = os.RemoveAll(postBackupOutFile)
755762

756763
msg = fmt.Sprintf("%s %s pre-backup", id, target.String())
757764
if _, err := os.Stat(preBackupOutFile); err != nil {
758765
t.Errorf("%s script didn't run, output file doesn't exist", msg)
759766
}
760-
os.RemoveAll(preBackupOutFile)
767+
_ = os.RemoveAll(preBackupOutFile)
761768
}
762769
p := target.Path()
763770
if p == "" {
@@ -803,8 +810,6 @@ func checkDumpTest(t *testing.T, base string, expected []byte, s3backend gofakes
803810
// to each format
804811
assert.Equal(t, expectedFiltered, string(b), "%s tar contents do not match actual dump", id)
805812
}
806-
807-
return
808813
}
809814

810815
// 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) {
815820
if err != nil {
816821
return nil, err
817822
}
818-
defer gr.Close()
823+
defer func() {
824+
_ = gr.Close()
825+
}()
819826
tr := tar.NewReader(gr)
820827
if _, err := tr.Next(); err != nil {
821828
return nil, err
@@ -884,12 +891,12 @@ func populatePrePost(base string, targets []backupTarget) (err error) {
884891
}
885892

886893
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{})
888895
if err != nil {
889896
return containerPort{}, fmt.Errorf("failed to pull mysql image: %v", err)
890897
}
891-
io.Copy(os.Stdout, resp)
892-
resp.Close()
898+
_, _ = io.Copy(os.Stdout, resp)
899+
_ = resp.Close()
893900

894901
// start the mysql container; configure it for lots of debug logging, in case we need it
895902
mysqlConf := `

0 commit comments

Comments
 (0)