From b5511e8e4c4231bb4b746ec727c963b527fe896f Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Thu, 8 Jun 2023 19:35:20 +0200 Subject: [PATCH] Fix linter warnings --- internal/backend/azure/azure_test.go | 6 ++-- internal/backend/b2/b2_test.go | 6 ++-- internal/backend/gs/gs_test.go | 6 ++-- internal/backend/rest/rest_test.go | 11 +++--- internal/backend/s3/s3_test.go | 52 +++++++++++++--------------- internal/backend/test/tests.go | 2 +- 6 files changed, 38 insertions(+), 45 deletions(-) diff --git a/internal/backend/azure/azure_test.go b/internal/backend/azure/azure_test.go index 8465cc3b0..33f65bd52 100644 --- a/internal/backend/azure/azure_test.go +++ b/internal/backend/azure/azure_test.go @@ -17,7 +17,7 @@ import ( rtest "github.com/restic/restic/internal/test" ) -func newAzureTestSuite(t testing.TB) *test.Suite[azure.Config] { +func newAzureTestSuite() *test.Suite[azure.Config] { return &test.Suite[azure.Config]{ // do not use excessive data MinimalData: true, @@ -59,7 +59,7 @@ func TestBackendAzure(t *testing.T) { } t.Logf("run tests") - newAzureTestSuite(t).RunTests(t) + newAzureTestSuite().RunTests(t) } func BenchmarkBackendAzure(t *testing.B) { @@ -77,7 +77,7 @@ func BenchmarkBackendAzure(t *testing.B) { } t.Logf("run tests") - newAzureTestSuite(t).RunBenchmarks(t) + newAzureTestSuite().RunBenchmarks(t) } func TestUploadLargeFile(t *testing.T) { diff --git a/internal/backend/b2/b2_test.go b/internal/backend/b2/b2_test.go index 348af9095..ab1dcd37b 100644 --- a/internal/backend/b2/b2_test.go +++ b/internal/backend/b2/b2_test.go @@ -12,7 +12,7 @@ import ( rtest "github.com/restic/restic/internal/test" ) -func newB2TestSuite(t testing.TB) *test.Suite[b2.Config] { +func newB2TestSuite() *test.Suite[b2.Config] { return &test.Suite[b2.Config]{ // do not use excessive data MinimalData: true, @@ -59,10 +59,10 @@ func TestBackendB2(t *testing.T) { }() testVars(t) - newB2TestSuite(t).RunTests(t) + newB2TestSuite().RunTests(t) } func BenchmarkBackendb2(t *testing.B) { testVars(t) - newB2TestSuite(t).RunBenchmarks(t) + newB2TestSuite().RunBenchmarks(t) } diff --git a/internal/backend/gs/gs_test.go b/internal/backend/gs/gs_test.go index 47085dc4e..22953cad3 100644 --- a/internal/backend/gs/gs_test.go +++ b/internal/backend/gs/gs_test.go @@ -11,7 +11,7 @@ import ( rtest "github.com/restic/restic/internal/test" ) -func newGSTestSuite(t testing.TB) *test.Suite[gs.Config] { +func newGSTestSuite() *test.Suite[gs.Config] { return &test.Suite[gs.Config]{ // do not use excessive data MinimalData: true, @@ -56,7 +56,7 @@ func TestBackendGS(t *testing.T) { } t.Logf("run tests") - newGSTestSuite(t).RunTests(t) + newGSTestSuite().RunTests(t) } func BenchmarkBackendGS(t *testing.B) { @@ -77,5 +77,5 @@ func BenchmarkBackendGS(t *testing.B) { } t.Logf("run tests") - newGSTestSuite(t).RunBenchmarks(t) + newGSTestSuite().RunBenchmarks(t) } diff --git a/internal/backend/rest/rest_test.go b/internal/backend/rest/rest_test.go index 60cc40afe..6a5b4f8a5 100644 --- a/internal/backend/rest/rest_test.go +++ b/internal/backend/rest/rest_test.go @@ -65,7 +65,7 @@ func runRESTServer(ctx context.Context, t testing.TB, dir string) (*url.URL, fun return url, cleanup } -func newTestSuite(_ context.Context, t testing.TB, url *url.URL, minimalData bool) *test.Suite[rest.Config] { +func newTestSuite(url *url.URL, minimalData bool) *test.Suite[rest.Config] { return &test.Suite[rest.Config]{ MinimalData: minimalData, @@ -94,7 +94,7 @@ func TestBackendREST(t *testing.T) { serverURL, cleanup := runRESTServer(ctx, t, dir) defer cleanup() - newTestSuite(ctx, t, serverURL, false).RunTests(t) + newTestSuite(serverURL, false).RunTests(t) } func TestBackendRESTExternalServer(t *testing.T) { @@ -108,10 +108,7 @@ func TestBackendRESTExternalServer(t *testing.T) { t.Fatal(err) } - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - - newTestSuite(ctx, t, cfg.URL, true).RunTests(t) + newTestSuite(cfg.URL, true).RunTests(t) } func BenchmarkBackendREST(t *testing.B) { @@ -122,5 +119,5 @@ func BenchmarkBackendREST(t *testing.B) { serverURL, cleanup := runRESTServer(ctx, t, dir) defer cleanup() - newTestSuite(ctx, t, serverURL, false).RunBenchmarks(t) + newTestSuite(serverURL, false).RunBenchmarks(t) } diff --git a/internal/backend/s3/s3_test.go b/internal/backend/s3/s3_test.go index e645fe03e..17f5f7016 100644 --- a/internal/backend/s3/s3_test.go +++ b/internal/backend/s3/s3_test.go @@ -94,35 +94,31 @@ func newRandomCredentials(t testing.TB) (key, secret string) { return key, secret } -func newMinioTestSuite(ctx context.Context, t testing.TB, key string, secret string) *test.Suite[s3.Config] { - return &test.Suite[s3.Config]{ - // NewConfig returns a config for a new temporary backend that will be used in tests. - NewConfig: func() (*s3.Config, error) { - cfg := s3.NewConfig() - cfg.Endpoint = "localhost:9000" - cfg.Bucket = "restictestbucket" - cfg.Prefix = fmt.Sprintf("test-%d", time.Now().UnixNano()) - cfg.UseHTTP = true - cfg.KeyID = key - cfg.Secret = options.NewSecretString(secret) - return &cfg, nil - }, - - Factory: s3.NewFactory(), - } -} - -func createMinioTestSuite(t testing.TB) (*test.Suite[s3.Config], func()) { +func newMinioTestSuite(t testing.TB) (*test.Suite[s3.Config], func()) { ctx, cancel := context.WithCancel(context.Background()) tempdir := rtest.TempDir(t) key, secret := newRandomCredentials(t) cleanup := runMinio(ctx, t, tempdir, key, secret) - return newMinioTestSuite(ctx, t, key, secret), func() { - defer cancel() - defer cleanup() - } + return &test.Suite[s3.Config]{ + // NewConfig returns a config for a new temporary backend that will be used in tests. + NewConfig: func() (*s3.Config, error) { + cfg := s3.NewConfig() + cfg.Endpoint = "localhost:9000" + cfg.Bucket = "restictestbucket" + cfg.Prefix = fmt.Sprintf("test-%d", time.Now().UnixNano()) + cfg.UseHTTP = true + cfg.KeyID = key + cfg.Secret = options.NewSecretString(secret) + return &cfg, nil + }, + + Factory: s3.NewFactory(), + }, func() { + defer cancel() + defer cleanup() + } } func TestBackendMinio(t *testing.T) { @@ -139,7 +135,7 @@ func TestBackendMinio(t *testing.T) { return } - suite, cleanup := createMinioTestSuite(t) + suite, cleanup := newMinioTestSuite(t) defer cleanup() suite.RunTests(t) @@ -153,13 +149,13 @@ func BenchmarkBackendMinio(t *testing.B) { return } - suite, cleanup := createMinioTestSuite(t) + suite, cleanup := newMinioTestSuite(t) defer cleanup() suite.RunBenchmarks(t) } -func newS3TestSuite(t testing.TB) *test.Suite[s3.Config] { +func newS3TestSuite() *test.Suite[s3.Config] { return &test.Suite[s3.Config]{ // do not use excessive data MinimalData: true, @@ -202,7 +198,7 @@ func TestBackendS3(t *testing.T) { } t.Logf("run tests") - newS3TestSuite(t).RunTests(t) + newS3TestSuite().RunTests(t) } func BenchmarkBackendS3(t *testing.B) { @@ -220,5 +216,5 @@ func BenchmarkBackendS3(t *testing.B) { } t.Logf("run tests") - newS3TestSuite(t).RunBenchmarks(t) + newS3TestSuite().RunBenchmarks(t) } diff --git a/internal/backend/test/tests.go b/internal/backend/test/tests.go index 14faad0d5..c2e5d0fc0 100644 --- a/internal/backend/test/tests.go +++ b/internal/backend/test/tests.go @@ -38,7 +38,7 @@ func beTest(ctx context.Context, be restic.Backend, h restic.Handle) (bool, erro // TestStripPasswordCall tests that the StripPassword method of a factory can be called without crashing. // It does not verify whether passwords are removed correctly -func (s *Suite[C]) TestStripPasswordCall(t *testing.T) { +func (s *Suite[C]) TestStripPasswordCall(_ *testing.T) { s.Factory.StripPassword("some random string") }