diff options
author | Steve Moyer <smoyer1@selesy.com> | 2022-06-15 10:23:33 -0400 |
---|---|---|
committer | Steve Moyer <smoyer1@selesy.com> | 2022-06-15 10:23:33 -0400 |
commit | d853a6fbc996762ab264452150558bb92bdbd6fc (patch) | |
tree | 300aa22a066100c1fbfa7a1218480c5550e08222 /commands/env_testing.go | |
parent | 0a9aaa94429172d14297f709ec2137cd3749cfea (diff) | |
download | git-bug-d853a6fbc996762ab264452150558bb92bdbd6fc.tar.gz |
test(778): simplify and guarantee backend cleanup
Diffstat (limited to 'commands/env_testing.go')
-rw-r--r-- | commands/env_testing.go | 22 |
1 files changed, 4 insertions, 18 deletions
diff --git a/commands/env_testing.go b/commands/env_testing.go index 092ff233..4de66a9d 100644 --- a/commands/env_testing.go +++ b/commands/env_testing.go @@ -8,7 +8,6 @@ import ( "github.com/MichaelMure/git-bug/cache" "github.com/MichaelMure/git-bug/repository" - "github.com/MichaelMure/git-bug/util/interrupt" ) type testEnv struct { @@ -32,8 +31,11 @@ func newTestEnv(t *testing.T) *testEnv { backend, err := cache.NewRepoCache(repo) require.NoError(t, err) + t.Cleanup(func() { + backend.Close() + }) - testEnv := &testEnv{ + return &testEnv{ env: &Env{ repo: repo, backend: backend, @@ -43,20 +45,4 @@ func newTestEnv(t *testing.T) *testEnv { cwd: cwd, out: buf, } - - cleaner := func(env *Env) interrupt.CleanerFunc { - return func() error { - if env.backend != nil { - err := env.backend.Close() - env.backend = nil - return err - } - return nil - } - } - - // Cleanup properly on interrupt - interrupt.RegisterCleaner(cleaner(testEnv.env)) - - return testEnv } |