6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-04 14:31:49 +00:00

Use t.Cleanup instead of defer to cleanup after tests

This commit is contained in:
Grzegorz Dlugoszewski
2020-05-18 22:49:33 +02:00
parent 4ce4381c57
commit 242d17ceb5
2 changed files with 4 additions and 9 deletions

View File

@@ -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
}

View File

@@ -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")