Fix linter warnings

This commit is contained in:
Michael Eischer 2023-06-08 19:35:20 +02:00
parent 50e0d5e6b5
commit b5511e8e4c
6 changed files with 38 additions and 45 deletions

View file

@ -17,7 +17,7 @@ import (
rtest "github.com/restic/restic/internal/test" 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]{ return &test.Suite[azure.Config]{
// do not use excessive data // do not use excessive data
MinimalData: true, MinimalData: true,
@ -59,7 +59,7 @@ func TestBackendAzure(t *testing.T) {
} }
t.Logf("run tests") t.Logf("run tests")
newAzureTestSuite(t).RunTests(t) newAzureTestSuite().RunTests(t)
} }
func BenchmarkBackendAzure(t *testing.B) { func BenchmarkBackendAzure(t *testing.B) {
@ -77,7 +77,7 @@ func BenchmarkBackendAzure(t *testing.B) {
} }
t.Logf("run tests") t.Logf("run tests")
newAzureTestSuite(t).RunBenchmarks(t) newAzureTestSuite().RunBenchmarks(t)
} }
func TestUploadLargeFile(t *testing.T) { func TestUploadLargeFile(t *testing.T) {

View file

@ -12,7 +12,7 @@ import (
rtest "github.com/restic/restic/internal/test" 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]{ return &test.Suite[b2.Config]{
// do not use excessive data // do not use excessive data
MinimalData: true, MinimalData: true,
@ -59,10 +59,10 @@ func TestBackendB2(t *testing.T) {
}() }()
testVars(t) testVars(t)
newB2TestSuite(t).RunTests(t) newB2TestSuite().RunTests(t)
} }
func BenchmarkBackendb2(t *testing.B) { func BenchmarkBackendb2(t *testing.B) {
testVars(t) testVars(t)
newB2TestSuite(t).RunBenchmarks(t) newB2TestSuite().RunBenchmarks(t)
} }

View file

@ -11,7 +11,7 @@ import (
rtest "github.com/restic/restic/internal/test" 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]{ return &test.Suite[gs.Config]{
// do not use excessive data // do not use excessive data
MinimalData: true, MinimalData: true,
@ -56,7 +56,7 @@ func TestBackendGS(t *testing.T) {
} }
t.Logf("run tests") t.Logf("run tests")
newGSTestSuite(t).RunTests(t) newGSTestSuite().RunTests(t)
} }
func BenchmarkBackendGS(t *testing.B) { func BenchmarkBackendGS(t *testing.B) {
@ -77,5 +77,5 @@ func BenchmarkBackendGS(t *testing.B) {
} }
t.Logf("run tests") t.Logf("run tests")
newGSTestSuite(t).RunBenchmarks(t) newGSTestSuite().RunBenchmarks(t)
} }

View file

@ -65,7 +65,7 @@ func runRESTServer(ctx context.Context, t testing.TB, dir string) (*url.URL, fun
return url, cleanup 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]{ return &test.Suite[rest.Config]{
MinimalData: minimalData, MinimalData: minimalData,
@ -94,7 +94,7 @@ func TestBackendREST(t *testing.T) {
serverURL, cleanup := runRESTServer(ctx, t, dir) serverURL, cleanup := runRESTServer(ctx, t, dir)
defer cleanup() defer cleanup()
newTestSuite(ctx, t, serverURL, false).RunTests(t) newTestSuite(serverURL, false).RunTests(t)
} }
func TestBackendRESTExternalServer(t *testing.T) { func TestBackendRESTExternalServer(t *testing.T) {
@ -108,10 +108,7 @@ func TestBackendRESTExternalServer(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
ctx, cancel := context.WithCancel(context.Background()) newTestSuite(cfg.URL, true).RunTests(t)
defer cancel()
newTestSuite(ctx, t, cfg.URL, true).RunTests(t)
} }
func BenchmarkBackendREST(t *testing.B) { func BenchmarkBackendREST(t *testing.B) {
@ -122,5 +119,5 @@ func BenchmarkBackendREST(t *testing.B) {
serverURL, cleanup := runRESTServer(ctx, t, dir) serverURL, cleanup := runRESTServer(ctx, t, dir)
defer cleanup() defer cleanup()
newTestSuite(ctx, t, serverURL, false).RunBenchmarks(t) newTestSuite(serverURL, false).RunBenchmarks(t)
} }

View file

@ -94,7 +94,13 @@ func newRandomCredentials(t testing.TB) (key, secret string) {
return key, secret return key, secret
} }
func newMinioTestSuite(ctx context.Context, t testing.TB, key string, secret string) *test.Suite[s3.Config] { 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 &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 returns a config for a new temporary backend that will be used in tests.
NewConfig: func() (*s3.Config, error) { NewConfig: func() (*s3.Config, error) {
@ -109,17 +115,7 @@ func newMinioTestSuite(ctx context.Context, t testing.TB, key string, secret str
}, },
Factory: s3.NewFactory(), Factory: s3.NewFactory(),
} }, func() {
}
func createMinioTestSuite(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 cancel()
defer cleanup() defer cleanup()
} }
@ -139,7 +135,7 @@ func TestBackendMinio(t *testing.T) {
return return
} }
suite, cleanup := createMinioTestSuite(t) suite, cleanup := newMinioTestSuite(t)
defer cleanup() defer cleanup()
suite.RunTests(t) suite.RunTests(t)
@ -153,13 +149,13 @@ func BenchmarkBackendMinio(t *testing.B) {
return return
} }
suite, cleanup := createMinioTestSuite(t) suite, cleanup := newMinioTestSuite(t)
defer cleanup() defer cleanup()
suite.RunBenchmarks(t) suite.RunBenchmarks(t)
} }
func newS3TestSuite(t testing.TB) *test.Suite[s3.Config] { func newS3TestSuite() *test.Suite[s3.Config] {
return &test.Suite[s3.Config]{ return &test.Suite[s3.Config]{
// do not use excessive data // do not use excessive data
MinimalData: true, MinimalData: true,
@ -202,7 +198,7 @@ func TestBackendS3(t *testing.T) {
} }
t.Logf("run tests") t.Logf("run tests")
newS3TestSuite(t).RunTests(t) newS3TestSuite().RunTests(t)
} }
func BenchmarkBackendS3(t *testing.B) { func BenchmarkBackendS3(t *testing.B) {
@ -220,5 +216,5 @@ func BenchmarkBackendS3(t *testing.B) {
} }
t.Logf("run tests") t.Logf("run tests")
newS3TestSuite(t).RunBenchmarks(t) newS3TestSuite().RunBenchmarks(t)
} }

View file

@ -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. // TestStripPasswordCall tests that the StripPassword method of a factory can be called without crashing.
// It does not verify whether passwords are removed correctly // 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") s.Factory.StripPassword("some random string")
} }