aboutsummaryrefslogtreecommitdiffstats
path: root/repository/gogit_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'repository/gogit_test.go')
-rw-r--r--repository/gogit_test.go49
1 files changed, 44 insertions, 5 deletions
diff --git a/repository/gogit_test.go b/repository/gogit_test.go
index a2bb49b9..c376de22 100644
--- a/repository/gogit_test.go
+++ b/repository/gogit_test.go
@@ -15,19 +15,25 @@ func TestNewGoGitRepo(t *testing.T) {
// Plain
plainRoot, err := ioutil.TempDir("", "")
require.NoError(t, err)
- defer os.RemoveAll(plainRoot)
+ t.Cleanup(func() {
+ require.NoError(t, os.RemoveAll(plainRoot))
+ })
- _, err = InitGoGitRepo(plainRoot)
+ plainRepo, err := InitGoGitRepo(plainRoot, namespace)
require.NoError(t, err)
+ require.NoError(t, plainRepo.Close())
plainGitDir := filepath.Join(plainRoot, ".git")
// Bare
bareRoot, err := ioutil.TempDir("", "")
require.NoError(t, err)
- defer os.RemoveAll(bareRoot)
+ t.Cleanup(func() {
+ require.NoError(t, os.RemoveAll(bareRoot))
+ })
- _, err = InitBareGoGitRepo(bareRoot)
+ bareRepo, err := InitBareGoGitRepo(bareRoot, namespace)
require.NoError(t, err)
+ require.NoError(t, bareRepo.Close())
bareGitDir := bareRoot
tests := []struct {
@@ -52,13 +58,14 @@ func TestNewGoGitRepo(t *testing.T) {
}
for i, tc := range tests {
- r, err := OpenGoGitRepo(tc.inPath, nil)
+ r, err := OpenGoGitRepo(tc.inPath, namespace, nil)
if tc.err {
require.Error(t, err, i)
} else {
require.NoError(t, err, i)
assert.Equal(t, filepath.ToSlash(tc.outPath), filepath.ToSlash(r.path), i)
+ require.NoError(t, r.Close())
}
}
}
@@ -66,3 +73,35 @@ func TestNewGoGitRepo(t *testing.T) {
func TestGoGitRepo(t *testing.T) {
RepoTest(t, CreateGoGitTestRepo, CleanupTestRepos)
}
+
+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())
+ })
+
+ // Can create indices
+ indexA, err := repo.GetBleveIndex("a")
+ require.NoError(t, err)
+ require.NotZero(t, indexA)
+ require.FileExists(t, filepath.Join(plainRoot, ".git", namespace, "indexes", "a", "index_meta.json"))
+ require.FileExists(t, filepath.Join(plainRoot, ".git", namespace, "indexes", "a", "store"))
+
+ indexB, err := repo.GetBleveIndex("b")
+ require.NoError(t, err)
+ require.NotZero(t, indexB)
+ require.DirExists(t, filepath.Join(plainRoot, ".git", namespace, "indexes", "b"))
+
+ // Can get an existing index
+ indexA, err = repo.GetBleveIndex("a")
+ require.NoError(t, err)
+ require.NotZero(t, indexA)
+
+ // Can delete an index
+ err = repo.ClearBleveIndex("a")
+ require.NoError(t, err)
+ require.NoDirExists(t, filepath.Join(plainRoot, ".git", namespace, "indexes", "a"))
+}