From 1cb11ad8add274cfb727bf41c2933903848d5b9a Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Mon, 1 May 2023 18:03:17 +0200 Subject: [PATCH] mount: enable debug logging for the flaky TestMount test The test case fails from time to time with an Input/Output error while trying to access the snapshots directory. --- cmd/restic/integration_fuse_test.go | 6 ++++++ internal/debug/testing.go | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 internal/debug/testing.go diff --git a/cmd/restic/integration_fuse_test.go b/cmd/restic/integration_fuse_test.go index a99064b8f..b69886024 100644 --- a/cmd/restic/integration_fuse_test.go +++ b/cmd/restic/integration_fuse_test.go @@ -12,6 +12,7 @@ import ( "testing" "time" + "github.com/restic/restic/internal/debug" "github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/restic" rtest "github.com/restic/restic/internal/test" @@ -159,6 +160,11 @@ func TestMount(t *testing.T) { t.Skip("Skipping fuse tests") } + debugEnabled := debug.TestLogToStderr(t) + if debugEnabled { + defer debug.TestDisableLog(t) + } + env, cleanup := withTestEnvironment(t) // must list snapshots more than once env.gopts.backendTestHook = nil diff --git a/internal/debug/testing.go b/internal/debug/testing.go new file mode 100644 index 000000000..c9ceae0ea --- /dev/null +++ b/internal/debug/testing.go @@ -0,0 +1,23 @@ +package debug + +import ( + "log" + "os" + "testing" +) + +// TestLogToStderr configures debug to log to stderr if not the debug log is +// not already configured and returns whether logging was enabled. +func TestLogToStderr(t testing.TB) bool { + if opts.isEnabled { + return false + } + opts.logger = log.New(os.Stderr, "", log.LstdFlags) + opts.isEnabled = true + return true +} + +func TestDisableLog(t testing.TB) { + opts.logger = nil + opts.isEnabled = false +}