6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-05 23:27:56 +00:00

Add CloneRepo function and unit tests for cloned repos status

This commit is contained in:
Grzegorz Dlugoszewski
2020-05-19 14:12:38 +02:00
parent a0f09ef74d
commit dfc8437408
5 changed files with 130 additions and 32 deletions

View File

@@ -18,24 +18,26 @@ func checkFatal(t *testing.T, err error) {
}
}
func cleanupRepo(t *testing.T, repo *git.Repository) {
err := os.RemoveAll(repo.Workdir())
if err != nil {
t.Errorf("failed cleaning up repo")
}
}
func newTestRepo(t *testing.T) *git.Repository {
dir, err := ioutil.TempDir("", "test-repo-")
func newTempDir(t *testing.T) string {
dir, err := ioutil.TempDir("", "git-get-repo-")
checkFatal(t, errors.Wrap(err, "Failed creating test repo directory"))
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)
err := os.RemoveAll(dir)
if err != nil {
t.Errorf("failed cleaning up repo")
}
})
return dir
}
func newTestRepo(t *testing.T) *git.Repository {
dir := newTempDir(t)
repo, err := git.InitRepository(dir, false)
checkFatal(t, errors.Wrap(err, "Failed initializing a temp repo"))
return repo
}