diff --git a/helpers_test.go b/helpers_test.go index 1152b81..b500eb5 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -32,6 +32,10 @@ func newTestRepo(t *testing.T) *git.Repository { repo, err := git.InitRepository(dir, false) checkFatal(t, errors.Wrap(err, "Failed initializing a temp repo")) + // Automatically remove repo when test is over + t.Cleanup(func() { + cleanupRepo(t, repo) + }) return repo } diff --git a/status_test.go b/status_test.go index 96417b2..ae7ad08 100644 --- a/status_test.go +++ b/status_test.go @@ -8,7 +8,6 @@ import ( func TestStatusWithEmptyRepo(t *testing.T) { repo := newTestRepo(t) - defer cleanupRepo(t, repo) entries, err := statusEntries(repo) checkFatal(t, err) @@ -27,8 +26,6 @@ func TestStatusWithEmptyRepo(t *testing.T) { func TestStatusWithUntrackedFile(t *testing.T) { repo := newTestRepo(t) - defer cleanupRepo(t, repo) - createFile(t, repo, "SomeFile") entries, err := statusEntries(repo) @@ -60,8 +57,6 @@ func TestStatusWithUntrackedButIgnoredFile(t *testing.T) { func TestStatusWithStagedFile(t *testing.T) { repo := newTestRepo(t) - defer cleanupRepo(t, repo) - createFile(t, repo, "SomeFile") stageFile(t, repo, "SomeFile") @@ -86,8 +81,6 @@ func TestStatusWithStagedFile(t *testing.T) { func TestStatusWithSingleCommit(t *testing.T) { repo := newTestRepo(t) - defer cleanupRepo(t, repo) - createFile(t, repo, "SomeFile") stageFile(t, repo, "SomeFile") createCommit(t, repo, "Initial commit") @@ -109,8 +102,6 @@ func TestStatusWithSingleCommit(t *testing.T) { func TestStatusWithMultipleCommits(t *testing.T) { repo := newTestRepo(t) - defer cleanupRepo(t, repo) - createFile(t, repo, "SomeFile") stageFile(t, repo, "SomeFile") createCommit(t, repo, "Initial commit")