test: Use testing.T.Cleanup to remove tempdirs

This commit is contained in:
greatroar 2022-12-09 13:42:33 +01:00
parent eae7366563
commit f90bf84ba7
31 changed files with 79 additions and 176 deletions

View file

@ -101,9 +101,8 @@ func newRandomCredentials(t testing.TB) (key, secret string) {
type MinioTestConfig struct {
s3.Config
tempdir string
removeTempdir func()
stopServer func()
tempdir string
stopServer func()
}
func createS3(t testing.TB, cfg MinioTestConfig, tr http.RoundTripper) (be restic.Backend, err error) {
@ -132,7 +131,7 @@ func newMinioTestSuite(ctx context.Context, t testing.TB) *test.Suite {
NewConfig: func() (interface{}, error) {
cfg := MinioTestConfig{}
cfg.tempdir, cfg.removeTempdir = rtest.TempDir(t)
cfg.tempdir = rtest.TempDir(t)
key, secret := newRandomCredentials(t)
cfg.stopServer = runMinio(ctx, t, cfg.tempdir, key, secret)
@ -179,9 +178,6 @@ func newMinioTestSuite(ctx context.Context, t testing.TB) *test.Suite {
if cfg.stopServer != nil {
cfg.stopServer()
}
if cfg.removeTempdir != nil {
cfg.removeTempdir()
}
return nil
},
}