From 403e201e1a0f5c9c875f589abf67cae2a6ce8f56 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 14 May 2017 12:50:20 +0200 Subject: [PATCH] tests: Improve robustness of config tests --- src/restic/backend/test/tests.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/restic/backend/test/tests.go b/src/restic/backend/test/tests.go index aa24db970..9110b0cf9 100644 --- a/src/restic/backend/test/tests.go +++ b/src/restic/backend/test/tests.go @@ -25,11 +25,22 @@ func BackendTestCreateWithConfig(t testing.TB, s *Suite) { b := s.open(t) defer s.close(t, b) + // remove a config if present + cfgHandle := restic.Handle{Type: restic.ConfigFile} + cfgPresent, err := b.Test(cfgHandle) + if err != nil { + t.Fatalf("unable to test for config: %+v", err) + } + + if cfgPresent { + remove(t, b, cfgHandle) + } + // save a config store(t, b, restic.ConfigFile, []byte("test config")) // now create the backend again, this must fail - _, err := s.Create(s.Config) + _, err = s.Create(s.Config) if err == nil { t.Fatalf("expected error not found for creating a backend with an existing config file") } @@ -83,6 +94,9 @@ func BackendTestConfig(t testing.TB, s *Suite) { t.Fatalf("wrong data returned, want %q, got %q", testString, string(buf)) } } + + // remove the config + remove(t, b, restic.Handle{Type: restic.ConfigFile}) } // BackendTestLoad tests the backend's Load function.