aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Moyer <smoyer1@selesy.com>2022-06-16 19:45:51 -0400
committerSteve Moyer <smoyer1@selesy.com>2022-06-16 19:45:51 -0400
commitf3d316d16cc9fadd90faaaf77becbb82f1e09367 (patch)
treec2774988393712b45c5e886bad01e67d61914ad0
parent97ae5448781ec57fcd41b0c3296c781054a036cb (diff)
downloadgit-bug-f3d316d16cc9fadd90faaaf77becbb82f1e09367.tar.gz
test(809): remove remaining calls to InitGoRepo in tests
Note that examples still need to shown how a developer would use the library.
-rw-r--r--commands/env_testing.go11
-rw-r--r--repository/gogit_test.go31
-rw-r--r--repository/gogit_testing.go17
3 files changed, 25 insertions, 34 deletions
diff --git a/commands/env_testing.go b/commands/env_testing.go
index b3c51c69..48807725 100644
--- a/commands/env_testing.go
+++ b/commands/env_testing.go
@@ -19,15 +19,8 @@ type testEnv struct {
func newTestEnv(t *testing.T) *testEnv {
t.Helper()
- cwd := t.TempDir()
-
- // r := repository.CreateGoGitTestRepo(t, false) // TODO
-
- repo, err := repository.InitGoGitRepo(cwd, gitBugNamespace)
- require.NoError(t, err)
- t.Cleanup(func() {
- require.NoError(t, repo.Close())
- })
+ repo := repository.CreateGoGitTestRepo(t, false)
+ cwd := repository.RepoDir(t, repo)
buf := new(bytes.Buffer)
diff --git a/repository/gogit_test.go b/repository/gogit_test.go
index 8179874c..5d3378b7 100644
--- a/repository/gogit_test.go
+++ b/repository/gogit_test.go
@@ -1,8 +1,6 @@
package repository
import (
- "io/ioutil"
- "os"
"path"
"path/filepath"
"testing"
@@ -13,26 +11,14 @@ import (
func TestNewGoGitRepo(t *testing.T) {
// Plain
- plainRoot, err := ioutil.TempDir("", "")
- require.NoError(t, err)
- t.Cleanup(func() {
- require.NoError(t, os.RemoveAll(plainRoot))
- })
-
- plainRepo, err := InitGoGitRepo(plainRoot, namespace)
- require.NoError(t, err)
+ plainRepo := CreateGoGitTestRepo(t, false)
+ plainRoot := RepoDir(t, plainRepo)
require.NoError(t, plainRepo.Close())
plainGitDir := filepath.Join(plainRoot, ".git")
// Bare
- bareRoot, err := ioutil.TempDir("", "")
- require.NoError(t, err)
- t.Cleanup(func() {
- require.NoError(t, os.RemoveAll(bareRoot))
- })
-
- bareRepo, err := InitBareGoGitRepo(bareRoot, namespace)
- require.NoError(t, err)
+ bareRepo := CreateGoGitTestRepo(t, true)
+ bareRoot := RepoDir(t, bareRepo)
require.NoError(t, bareRepo.Close())
bareGitDir := bareRoot
@@ -75,13 +61,8 @@ func TestGoGitRepo(t *testing.T) {
}
func TestGoGitRepo_Indexes(t *testing.T) {
- plainRoot := t.TempDir()
-
- repo, err := InitGoGitRepo(plainRoot, namespace)
- require.NoError(t, err)
- t.Cleanup(func() {
- require.NoError(t, repo.Close())
- })
+ repo := CreateGoGitTestRepo(t, false)
+ plainRoot := RepoDir(t, repo)
// Can create indices
indexA, err := repo.GetBleveIndex("a")
diff --git a/repository/gogit_testing.go b/repository/gogit_testing.go
index 1b39fe5c..01be54de 100644
--- a/repository/gogit_testing.go
+++ b/repository/gogit_testing.go
@@ -2,6 +2,8 @@ package repository
import (
"log"
+ "path/filepath"
+ "strings"
"testing"
"github.com/99designs/keyring"
@@ -73,3 +75,18 @@ func SetupGoGitReposAndRemote(t *testing.T) (repoA, repoB, remote TestedRepo) {
return repoA, repoB, remote
}
+
+func RepoDir(t *testing.T, repo TestedRepo) string {
+ t.Helper()
+
+ dir := repo.GetLocalRemote()
+ if strings.HasSuffix(dir, ".git") {
+ dir, _ = filepath.Split(dir)
+ }
+
+ if dir[len(dir)-1] == filepath.Separator {
+ dir = dir[:len(dir)-1]
+ }
+
+ return dir
+}