aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Moyer <smoyer1@selesy.com>2022-05-28 08:07:34 -0400
committerMichael Muré <batolettre@gmail.com>2022-05-31 12:04:26 +0200
commit86dd450aaf592aa065a17d49d70d9d0352fa5ca3 (patch)
tree2208f6854e7d7bed467d2360818bd5dba4d68344
parent8821b67d1bd0809d3fd3e87baf391e07aa54722a (diff)
downloadgit-bug-86dd450aaf592aa065a17d49d70d9d0352fa5ca3.tar.gz
test: clean up temp dir and repo correctly
-rw-r--r--entity/dag/example_test.go2
-rw-r--r--repository/gogit_test.go22
2 files changed, 19 insertions, 5 deletions
diff --git a/entity/dag/example_test.go b/entity/dag/example_test.go
index 106e359c..948d6aeb 100644
--- a/entity/dag/example_test.go
+++ b/entity/dag/example_test.go
@@ -344,7 +344,9 @@ func Example_entity() {
repoRenePath, _ := os.MkdirTemp("", "")
repoIsaacPath, _ := os.MkdirTemp("", "")
repoRene, _ := repository.InitGoGitRepo(repoRenePath, gitBugNamespace)
+ defer repoRene.Close()
repoIsaac, _ := repository.InitGoGitRepo(repoIsaacPath, gitBugNamespace)
+ defer repoIsaac.Close()
_ = repoRene.AddRemote("origin", repoIsaacPath)
_ = repoIsaac.AddRemote("origin", repoRenePath)
diff --git a/repository/gogit_test.go b/repository/gogit_test.go
index d7b919b9..49eae309 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, namespace)
+ 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, namespace)
+ bareRepo, err := InitBareGoGitRepo(bareRoot, namespace)
require.NoError(t, err)
+ require.NoError(t, bareRepo.Close())
bareGitDir := bareRoot
tests := []struct {
@@ -59,6 +65,7 @@ func TestNewGoGitRepo(t *testing.T) {
} else {
require.NoError(t, err, i)
assert.Equal(t, filepath.ToSlash(tc.outPath), filepath.ToSlash(r.path), i)
+ require.NoError(t, r.Close())
}
}
}
@@ -72,10 +79,15 @@ func TestGoGitRepo_Indexes(t *testing.T) {
plainRoot, err := ioutil.TempDir("", "")
require.NoError(t, err)
- // defer os.RemoveAll(plainRoot)
+ t.Cleanup(func() {
+ require.NoError(t, os.RemoveAll(plainRoot))
+ })
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")