Add more git url regression coverage

This commit is contained in:
Jeffrey Regan
2019-02-07 10:45:23 -08:00
parent 92bd809bc8
commit 1f063d6712
2 changed files with 47 additions and 34 deletions

View File

@@ -24,6 +24,13 @@ import (
"sigs.k8s.io/kustomize/pkg/fs" "sigs.k8s.io/kustomize/pkg/fs"
) )
// Used as a temporary non-empty occupant of the cloneDir
// field, as something distinguishable from the empty string
// in various outputs (especially tests). Not using an
// actual directory name here, as that's a temporary directory
// with a unique name that isn't created until clone time.
const notCloned = fs.ConfirmedDir("/notCloned")
// RepoSpec specifies a git repository and a branch and path therein. // RepoSpec specifies a git repository and a branch and path therein.
type RepoSpec struct { type RepoSpec struct {
// Raw, original spec, used to look for cycles. // Raw, original spec, used to look for cycles.
@@ -88,7 +95,7 @@ func NewRepoSpecFromUrl(n string) (*RepoSpec, error) {
} }
return &RepoSpec{ return &RepoSpec{
raw: n, host: host, orgRepo: orgRepo, raw: n, host: host, orgRepo: orgRepo,
path: path, ref: gitRef}, nil cloneDir: notCloned, path: path, ref: gitRef}, nil
} }
const ( const (

View File

@@ -123,59 +123,65 @@ func TestNewRepoSpecFromUrlErrors(t *testing.T) {
func TestNewRepoSpecFromUrl_CloneSpecs(t *testing.T) { func TestNewRepoSpecFromUrl_CloneSpecs(t *testing.T) {
testcases := []struct { testcases := []struct {
input string input string
repo string cloneSpec string
path string absPath string
ref string ref string
}{ }{
{ {
input: "https://git-codecommit.us-east-2.amazonaws.com/someorg/somerepo/somedir", input: "https://git-codecommit.us-east-2.amazonaws.com/someorg/somerepo/somedir",
repo: "https://git-codecommit.us-east-2.amazonaws.com/someorg/somerepo", cloneSpec: "https://git-codecommit.us-east-2.amazonaws.com/someorg/somerepo",
path: "somedir", absPath: notCloned.Join("somedir"),
ref: "", ref: "",
}, },
{ {
input: "https://git-codecommit.us-east-2.amazonaws.com/someorg/somerepo/somedir?ref=testbranch", input: "https://git-codecommit.us-east-2.amazonaws.com/someorg/somerepo/somedir?ref=testbranch",
repo: "https://git-codecommit.us-east-2.amazonaws.com/someorg/somerepo", cloneSpec: "https://git-codecommit.us-east-2.amazonaws.com/someorg/somerepo",
path: "somedir", absPath: notCloned.Join("somedir"),
ref: "testbranch", ref: "testbranch",
}, },
{ {
input: "https://fabrikops2.visualstudio.com/someorg/somerepo?ref=master", input: "https://fabrikops2.visualstudio.com/someorg/somerepo?ref=master",
repo: "https://fabrikops2.visualstudio.com/someorg/somerepo", cloneSpec: "https://fabrikops2.visualstudio.com/someorg/somerepo",
path: "", absPath: notCloned.String(),
ref: "master", ref: "master",
}, },
{ {
input: "http://github.com/someorg/somerepo/somedir", input: "http://github.com/someorg/somerepo/somedir",
repo: "https://github.com/someorg/somerepo.git", cloneSpec: "https://github.com/someorg/somerepo.git",
path: "somedir", absPath: notCloned.Join("somedir"),
ref: "", ref: "",
}, },
{ {
input: "git@github.com:someorg/somerepo/somedir", input: "git@github.com:someorg/somerepo/somedir",
repo: "git@github.com:someorg/somerepo.git", cloneSpec: "git@github.com:someorg/somerepo.git",
path: "somedir", absPath: notCloned.Join("somedir"),
ref: "", ref: "",
}, },
{ {
input: "git@gitlab2.sqtools.ru:10022/infra/kubernetes/thanos-base.git?ref=v0.1.0", input: "git@gitlab2.sqtools.ru:10022/infra/kubernetes/thanos-base.git?ref=v0.1.0",
repo: "git@gitlab2.sqtools.ru:10022/infra/kubernetes/thanos-base.git", cloneSpec: "git@gitlab2.sqtools.ru:10022/infra/kubernetes/thanos-base.git",
path: "", absPath: notCloned.String(),
ref: "v0.1.0", ref: "v0.1.0",
}, },
{
input: "git@bitbucket.org:company/project.git//path?ref=branch",
cloneSpec: "git@bitbucket.org:company/project.git",
absPath: notCloned.Join("path"),
ref: "branch",
},
} }
for _, testcase := range testcases { for _, testcase := range testcases {
rs, err := NewRepoSpecFromUrl(testcase.input) rs, err := NewRepoSpecFromUrl(testcase.input)
if err != nil { if err != nil {
t.Errorf("Unexpected error: %v", err) t.Errorf("Unexpected error: %v", err)
} }
if rs.CloneSpec() != testcase.repo { if rs.CloneSpec() != testcase.cloneSpec {
t.Errorf("CloneSpec expected to be %v, but got %v on %s", t.Errorf("CloneSpec expected to be %v, but got %v on %s",
testcase.repo, rs.CloneSpec(), testcase.input) testcase.cloneSpec, rs.CloneSpec(), testcase.input)
} }
if rs.path != testcase.path { if rs.AbsPath() != testcase.absPath {
t.Errorf("path expected to be %v, but got %v on %s", t.Errorf("AbsPath expected to be %v, but got %v on %s",
testcase.path, rs.path, testcase.input) testcase.absPath, rs.AbsPath(), testcase.input)
} }
if rs.ref != testcase.ref { if rs.ref != testcase.ref {
t.Errorf("ref expected to be %v, but got %v on %s", t.Errorf("ref expected to be %v, but got %v on %s",