aboutsummaryrefslogtreecommitdiffstats
path: root/repository/gogit_testing.go
diff options
context:
space:
mode:
Diffstat (limited to 'repository/gogit_testing.go')
-rw-r--r--repository/gogit_testing.go31
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 {