Introduce RepoSpec.

This PR closes a TODO in the fileLoader type to
replace the string representing a git repo url
with a struct called holding validated fields.

New struct is called RepoSpec.

It holds what we need in coming PRs for remote
repo base containment checks, and will also allow
the overlay cycle prevention code to take into
account different host schemes or branches.

The struct is in a new file called repospec.go.
The new file is mostly just a code move of url
parsing code that was in cloner.go.  Git "blame"
history preserved through the move.

No change in execution (see final commit by itself).
This commit is contained in:
jregan
2019-01-27 07:26:37 -08:00
parent 90b863d124
commit ad400cd13d
7 changed files with 104 additions and 522 deletions

View File

@@ -171,7 +171,7 @@ func TestParseGithubUrl(t *testing.T) {
}
}
func TestParseUrl(t *testing.T) {
func TestNewRepoSpecFromUrl(t *testing.T) {
testcases := []struct {
input string
repo string
@@ -216,18 +216,21 @@ func TestParseUrl(t *testing.T) {
},
}
for _, testcase := range testcases {
repo, path, ref, err := parseUrl(testcase.input)
rs, err := NewRepoSpecFromUrl(testcase.input)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
if repo != testcase.repo {
t.Errorf("repo expected to be %v, but got %v on %s", testcase.repo, repo, testcase.input)
if rs.repo != testcase.repo {
t.Errorf("repo expected to be %v, but got %v on %s",
testcase.repo, rs.repo, testcase.input)
}
if path != testcase.path {
t.Errorf("path expected to be %v, but got %v on %s", testcase.path, path, testcase.input)
if rs.path != testcase.path {
t.Errorf("path expected to be %v, but got %v on %s",
testcase.path, rs.path, testcase.input)
}
if ref != testcase.ref {
t.Errorf("ref expected to be %v, but got %v on %s", testcase.ref, ref, testcase.input)
if rs.ref != testcase.ref {
t.Errorf("ref expected to be %v, but got %v on %s",
testcase.ref, rs.ref, testcase.input)
}
}
}