6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-10 06:44:25 +00:00

Refactor repoFinder

- Remove io package and move finder to git package
- Move tempDir and writeFile into test package. They are only used for testing purposes anyway.
- Add a way to specify parent folder for tempDir. Useful for testing nested repos.
- Add new test repos with .git/config files
This commit is contained in:
Grzegorz Dlugoszewski
2020-07-08 13:37:32 +02:00
parent 5ab6031382
commit 8ab4681c26
8 changed files with 68 additions and 79 deletions

View File

@@ -1,8 +1,8 @@
package test
import (
"git-get/pkg/io"
"os"
"path/filepath"
"testing"
)
@@ -29,7 +29,7 @@ func (r *Repo) cleanup() {
// RepoEmpty creates an empty git repo.
func RepoEmpty(t *testing.T) *Repo {
dir, err := io.TempDir()
dir, err := tempDir("")
checkFatal(t, err)
r := &Repo{
@@ -178,3 +178,26 @@ func RepoWithBranchAheadAndBehind(t *testing.T) *Repo {
return r
}
// RepoWithEmptyConfig creates a git repo with empty .git/config file
func RepoWithEmptyConfig(t *testing.T) *Repo {
r := RepoEmpty(t)
r.writeFile(filepath.Join(".git", "config"), "")
return r
}
// RepoWithValidConfig creates a git repo with valid content in .git/config file
func RepoWithValidConfig(t *testing.T) *Repo {
r := RepoEmpty(t)
gitconfig := `
[user]
name = grdl
[gitget]
host = github.com
`
r.writeFile(filepath.Join(".git", "config"), gitconfig)
return r
}