test: add verification that localStorage.Root() resolves to the correct absolute filepath

This commit is contained in:
Steve Moyer 2022-05-26 13:40:52 -04:00
parent e120fdb97e
commit 8821b67d1b
No known key found for this signature in database
GPG Key ID: D8D464C9D22FB8E0

View File

@ -17,7 +17,7 @@ func TestNewGoGitRepo(t *testing.T) {
require.NoError(t, err)
defer os.RemoveAll(plainRoot)
_, err = InitGoGitRepo(plainRoot, testApplicationName)
_, err = InitGoGitRepo(plainRoot, namespace)
require.NoError(t, err)
plainGitDir := filepath.Join(plainRoot, ".git")
@ -26,7 +26,7 @@ func TestNewGoGitRepo(t *testing.T) {
require.NoError(t, err)
defer os.RemoveAll(bareRoot)
_, err = InitBareGoGitRepo(bareRoot, testApplicationName)
_, err = InitBareGoGitRepo(bareRoot, namespace)
require.NoError(t, err)
bareGitDir := bareRoot
@ -52,7 +52,7 @@ func TestNewGoGitRepo(t *testing.T) {
}
for i, tc := range tests {
r, err := OpenGoGitRepo(tc.inPath, testApplicationName, nil)
r, err := OpenGoGitRepo(tc.inPath, namespace, nil)
if tc.err {
require.Error(t, err, i)
@ -66,3 +66,36 @@ func TestNewGoGitRepo(t *testing.T) {
func TestGoGitRepo(t *testing.T) {
RepoTest(t, CreateGoGitTestRepo, CleanupTestRepos)
}
func TestGoGitRepo_Indexes(t *testing.T) {
t.Parallel()
plainRoot, err := ioutil.TempDir("", "")
require.NoError(t, err)
// defer os.RemoveAll(plainRoot)
repo, err := InitGoGitRepo(plainRoot, namespace)
require.NoError(t, err)
// 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"))
}