diff options
author | Steve Moyer <smoyer1@selesy.com> | 2022-06-16 09:02:52 -0400 |
---|---|---|
committer | Steve Moyer <smoyer1@selesy.com> | 2022-06-16 09:02:52 -0400 |
commit | 1d4667c825bb5d291070bd4463c39a16f950f674 (patch) | |
tree | 84f1101f4cddc3804955c2c2ff90e3687c1dafee /repository/gogit_testing.go | |
parent | d853a6fbc996762ab264452150558bb92bdbd6fc (diff) | |
download | git-bug-1d4667c825bb5d291070bd4463c39a16f950f674.tar.gz git-bug-1d4667c825bb5d291070bd4463c39a16f950f674.zip |
refactor(809): eliminate need to defer CleanupTestRepos()
Diffstat (limited to 'repository/gogit_testing.go')
-rw-r--r-- | repository/gogit_testing.go | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/repository/gogit_testing.go b/repository/gogit_testing.go index 7647c711..1b39fe5c 100644 --- a/repository/gogit_testing.go +++ b/repository/gogit_testing.go @@ -1,21 +1,26 @@ package repository import ( - "io/ioutil" "log" + "testing" "github.com/99designs/keyring" ) +type TestingT interface { + Cleanup(func()) + Helper() + TempDir() string +} + const namespace = "git-bug" // This is intended for testing only -func CreateGoGitTestRepo(bare bool) TestedRepo { - dir, err := ioutil.TempDir("", "") - if err != nil { - log.Fatal(err) - } +func CreateGoGitTestRepo(t TestingT, bare bool) TestedRepo { + t.Helper() + + dir := t.TempDir() var creator func(string, string) (*GoGitRepo, error) @@ -30,6 +35,10 @@ func CreateGoGitTestRepo(bare bool) TestedRepo { log.Fatal(err) } + t.Cleanup(func() { + repo.Close() + }) + config := repo.LocalConfig() if err := config.StoreString("user.name", "testuser"); err != nil { log.Fatal("failed to set user.name for test repository: ", err) @@ -45,10 +54,12 @@ func CreateGoGitTestRepo(bare bool) TestedRepo { } } -func SetupGoGitReposAndRemote() (repoA, repoB, remote TestedRepo) { - repoA = CreateGoGitTestRepo(false) - repoB = CreateGoGitTestRepo(false) - remote = CreateGoGitTestRepo(true) +func SetupGoGitReposAndRemote(t *testing.T) (repoA, repoB, remote TestedRepo) { + t.Helper() + + repoA = CreateGoGitTestRepo(t, false) + repoB = CreateGoGitTestRepo(t, false) + remote = CreateGoGitTestRepo(t, true) err := repoA.AddRemote("origin", remote.GetLocalRemote()) if err != nil { |