mirror of
https://github.com/grdl/git-get.git
synced 2026-02-04 17:24:49 +00:00
Use t.Cleanup instead of defer to cleanup after tests
This commit is contained in:
@@ -32,6 +32,10 @@ func newTestRepo(t *testing.T) *git.Repository {
|
|||||||
repo, err := git.InitRepository(dir, false)
|
repo, err := git.InitRepository(dir, false)
|
||||||
checkFatal(t, errors.Wrap(err, "Failed initializing a temp repo"))
|
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
|
return repo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
|
|
||||||
func TestStatusWithEmptyRepo(t *testing.T) {
|
func TestStatusWithEmptyRepo(t *testing.T) {
|
||||||
repo := newTestRepo(t)
|
repo := newTestRepo(t)
|
||||||
defer cleanupRepo(t, repo)
|
|
||||||
|
|
||||||
entries, err := statusEntries(repo)
|
entries, err := statusEntries(repo)
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
@@ -27,8 +26,6 @@ func TestStatusWithEmptyRepo(t *testing.T) {
|
|||||||
|
|
||||||
func TestStatusWithUntrackedFile(t *testing.T) {
|
func TestStatusWithUntrackedFile(t *testing.T) {
|
||||||
repo := newTestRepo(t)
|
repo := newTestRepo(t)
|
||||||
defer cleanupRepo(t, repo)
|
|
||||||
|
|
||||||
createFile(t, repo, "SomeFile")
|
createFile(t, repo, "SomeFile")
|
||||||
|
|
||||||
entries, err := statusEntries(repo)
|
entries, err := statusEntries(repo)
|
||||||
@@ -60,8 +57,6 @@ func TestStatusWithUntrackedButIgnoredFile(t *testing.T) {
|
|||||||
|
|
||||||
func TestStatusWithStagedFile(t *testing.T) {
|
func TestStatusWithStagedFile(t *testing.T) {
|
||||||
repo := newTestRepo(t)
|
repo := newTestRepo(t)
|
||||||
defer cleanupRepo(t, repo)
|
|
||||||
|
|
||||||
createFile(t, repo, "SomeFile")
|
createFile(t, repo, "SomeFile")
|
||||||
stageFile(t, repo, "SomeFile")
|
stageFile(t, repo, "SomeFile")
|
||||||
|
|
||||||
@@ -86,8 +81,6 @@ func TestStatusWithStagedFile(t *testing.T) {
|
|||||||
|
|
||||||
func TestStatusWithSingleCommit(t *testing.T) {
|
func TestStatusWithSingleCommit(t *testing.T) {
|
||||||
repo := newTestRepo(t)
|
repo := newTestRepo(t)
|
||||||
defer cleanupRepo(t, repo)
|
|
||||||
|
|
||||||
createFile(t, repo, "SomeFile")
|
createFile(t, repo, "SomeFile")
|
||||||
stageFile(t, repo, "SomeFile")
|
stageFile(t, repo, "SomeFile")
|
||||||
createCommit(t, repo, "Initial commit")
|
createCommit(t, repo, "Initial commit")
|
||||||
@@ -109,8 +102,6 @@ func TestStatusWithSingleCommit(t *testing.T) {
|
|||||||
|
|
||||||
func TestStatusWithMultipleCommits(t *testing.T) {
|
func TestStatusWithMultipleCommits(t *testing.T) {
|
||||||
repo := newTestRepo(t)
|
repo := newTestRepo(t)
|
||||||
defer cleanupRepo(t, repo)
|
|
||||||
|
|
||||||
createFile(t, repo, "SomeFile")
|
createFile(t, repo, "SomeFile")
|
||||||
stageFile(t, repo, "SomeFile")
|
stageFile(t, repo, "SomeFile")
|
||||||
createCommit(t, repo, "Initial commit")
|
createCommit(t, repo, "Initial commit")
|
||||||
|
|||||||
Reference in New Issue
Block a user