mirror of
https://github.com/restic/restic.git
synced 2025-10-09 15:30:24 +00:00
Merge pull request #4077 from greatroar/cleanup
test: Use testing.T.Cleanup to remove tempdirs
This commit is contained in:
@@ -14,8 +14,7 @@ import (
|
||||
)
|
||||
|
||||
func TestDefaultLayout(t *testing.T) {
|
||||
tempdir, cleanup := rtest.TempDir(t)
|
||||
defer cleanup()
|
||||
tempdir := rtest.TempDir(t)
|
||||
|
||||
var tests = []struct {
|
||||
path string
|
||||
@@ -141,8 +140,7 @@ func TestDefaultLayout(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRESTLayout(t *testing.T) {
|
||||
path, cleanup := rtest.TempDir(t)
|
||||
defer cleanup()
|
||||
path := rtest.TempDir(t)
|
||||
|
||||
var tests = []struct {
|
||||
restic.Handle
|
||||
@@ -287,8 +285,7 @@ func TestRESTLayoutURLs(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestS3LegacyLayout(t *testing.T) {
|
||||
path, cleanup := rtest.TempDir(t)
|
||||
defer cleanup()
|
||||
path := rtest.TempDir(t)
|
||||
|
||||
var tests = []struct {
|
||||
restic.Handle
|
||||
@@ -355,8 +352,7 @@ func TestS3LegacyLayout(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDetectLayout(t *testing.T) {
|
||||
path, cleanup := rtest.TempDir(t)
|
||||
defer cleanup()
|
||||
path := rtest.TempDir(t)
|
||||
|
||||
var tests = []struct {
|
||||
filename string
|
||||
@@ -393,8 +389,7 @@ func TestDetectLayout(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseLayout(t *testing.T) {
|
||||
path, cleanup := rtest.TempDir(t)
|
||||
defer cleanup()
|
||||
path := rtest.TempDir(t)
|
||||
|
||||
var tests = []struct {
|
||||
layoutName string
|
||||
@@ -433,8 +428,7 @@ func TestParseLayout(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseLayoutInvalid(t *testing.T) {
|
||||
path, cleanup := rtest.TempDir(t)
|
||||
defer cleanup()
|
||||
path := rtest.TempDir(t)
|
||||
|
||||
var invalidNames = []string{
|
||||
"foo", "bar", "local",
|
||||
|
@@ -10,8 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func TestLayout(t *testing.T) {
|
||||
path, cleanup := rtest.TempDir(t)
|
||||
defer cleanup()
|
||||
path := rtest.TempDir(t)
|
||||
|
||||
var tests = []struct {
|
||||
filename string
|
||||
|
@@ -24,8 +24,7 @@ func TestNoSpacePermanent(t *testing.T) {
|
||||
return nil, fmt.Errorf("not creating tempfile, %w", syscall.ENOSPC)
|
||||
}
|
||||
|
||||
dir, cleanup := rtest.TempDir(t)
|
||||
defer cleanup()
|
||||
dir := rtest.TempDir(t)
|
||||
|
||||
be, err := Open(context.Background(), Config{Path: dir, Connections: 2})
|
||||
rtest.OK(t, err)
|
||||
|
@@ -120,8 +120,7 @@ func removeAll(t testing.TB, dir string) {
|
||||
}
|
||||
|
||||
func TestOpenNotExistingDirectory(t *testing.T) {
|
||||
dir, cleanup := rtest.TempDir(t)
|
||||
defer cleanup()
|
||||
dir := rtest.TempDir(t)
|
||||
|
||||
// local.Open must not create any files dirs in the repo
|
||||
openclose(t, filepath.Join(dir, "repo"))
|
||||
|
@@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
func newTestSuite(t testing.TB) *test.Suite {
|
||||
dir, cleanup := rtest.TempDir(t)
|
||||
dir := rtest.TempDir(t)
|
||||
|
||||
return &test.Suite{
|
||||
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
||||
@@ -43,13 +43,6 @@ func newTestSuite(t testing.TB) *test.Suite {
|
||||
cfg := config.(rclone.Config)
|
||||
return rclone.Open(cfg, nil)
|
||||
},
|
||||
|
||||
// CleanupFn removes data created during the tests.
|
||||
Cleanup: func(config interface{}) error {
|
||||
t.Logf("cleanup dir %v", dir)
|
||||
cleanup()
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -12,9 +12,7 @@ import (
|
||||
|
||||
// restic should detect rclone exiting.
|
||||
func TestRcloneExit(t *testing.T) {
|
||||
dir, cleanup := rtest.TempDir(t)
|
||||
defer cleanup()
|
||||
|
||||
dir := rtest.TempDir(t)
|
||||
cfg := NewConfig()
|
||||
cfg.Remote = dir
|
||||
be, err := Open(cfg, nil)
|
||||
|
@@ -112,9 +112,7 @@ func TestBackendREST(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
dir, cleanup := rtest.TempDir(t)
|
||||
defer cleanup()
|
||||
|
||||
dir := rtest.TempDir(t)
|
||||
serverURL, cleanup := runRESTServer(ctx, t, dir)
|
||||
defer cleanup()
|
||||
|
||||
@@ -144,9 +142,7 @@ func BenchmarkBackendREST(t *testing.B) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
dir, cleanup := rtest.TempDir(t)
|
||||
defer cleanup()
|
||||
|
||||
dir := rtest.TempDir(t)
|
||||
serverURL, cleanup := runRESTServer(ctx, t, dir)
|
||||
defer cleanup()
|
||||
|
||||
|
@@ -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
|
||||
},
|
||||
}
|
||||
|
@@ -16,8 +16,7 @@ func TestLayout(t *testing.T) {
|
||||
t.Skip("sftp server binary not available")
|
||||
}
|
||||
|
||||
path, cleanup := rtest.TempDir(t)
|
||||
defer cleanup()
|
||||
path := rtest.TempDir(t)
|
||||
|
||||
var tests = []struct {
|
||||
filename string
|
||||
|
@@ -60,8 +60,10 @@ func (s *Suite) RunTests(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
if err = s.Cleanup(s.Config); err != nil {
|
||||
t.Fatal(err)
|
||||
if s.Cleanup != nil {
|
||||
if err = s.Cleanup(s.Config); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user