diff options
Diffstat (limited to 'libgo/go/cmd/go/internal/get/vcs_test.go')
-rw-r--r-- | libgo/go/cmd/go/internal/get/vcs_test.go | 133 |
1 files changed, 79 insertions, 54 deletions
diff --git a/libgo/go/cmd/go/internal/get/vcs_test.go b/libgo/go/cmd/go/internal/get/vcs_test.go index a6f8642026c..d13721bed1a 100644 --- a/libgo/go/cmd/go/internal/get/vcs_test.go +++ b/libgo/go/cmd/go/internal/get/vcs_test.go @@ -16,43 +16,43 @@ import ( "cmd/go/internal/web" ) -// Test that RepoRootForImportPath creates the correct RepoRoot for a given importPath. +// Test that RepoRootForImportPath determines the correct RepoRoot for a given importPath. // TODO(cmang): Add tests for SVN and BZR. func TestRepoRootForImportPath(t *testing.T) { testenv.MustHaveExternalNetwork(t) tests := []struct { path string - want *repoRoot + want *RepoRoot }{ { "github.com/golang/groupcache", - &repoRoot{ + &RepoRoot{ vcs: vcsGit, - repo: "https://github.com/golang/groupcache", + Repo: "https://github.com/golang/groupcache", }, }, // Unicode letters in directories (issue 18660). { "github.com/user/unicode/испытание", - &repoRoot{ + &RepoRoot{ vcs: vcsGit, - repo: "https://github.com/user/unicode", + Repo: "https://github.com/user/unicode", }, }, // IBM DevOps Services tests { "hub.jazz.net/git/user1/pkgname", - &repoRoot{ + &RepoRoot{ vcs: vcsGit, - repo: "https://hub.jazz.net/git/user1/pkgname", + Repo: "https://hub.jazz.net/git/user1/pkgname", }, }, { "hub.jazz.net/git/user1/pkgname/submodule/submodule/submodule", - &repoRoot{ + &RepoRoot{ vcs: vcsGit, - repo: "https://hub.jazz.net/git/user1/pkgname", + Repo: "https://hub.jazz.net/git/user1/pkgname", }, }, { @@ -60,6 +60,10 @@ func TestRepoRootForImportPath(t *testing.T) { nil, }, { + "hubajazz.net", + nil, + }, + { "hub2.jazz.net", nil, }, @@ -87,9 +91,9 @@ func TestRepoRootForImportPath(t *testing.T) { }, { "hub.jazz.net/git/user/pkg.name", - &repoRoot{ + &RepoRoot{ vcs: vcsGit, - repo: "https://hub.jazz.net/git/user/pkg.name", + Repo: "https://hub.jazz.net/git/user/pkg.name", }, }, // User names cannot have uppercase letters @@ -100,9 +104,9 @@ func TestRepoRootForImportPath(t *testing.T) { // OpenStack tests { "git.openstack.org/openstack/swift", - &repoRoot{ + &RepoRoot{ vcs: vcsGit, - repo: "https://git.openstack.org/openstack/swift", + Repo: "https://git.openstack.org/openstack/swift", }, }, // Trailing .git is less preferred but included for @@ -110,16 +114,16 @@ func TestRepoRootForImportPath(t *testing.T) { // be compilable on both old and new go { "git.openstack.org/openstack/swift.git", - &repoRoot{ + &RepoRoot{ vcs: vcsGit, - repo: "https://git.openstack.org/openstack/swift.git", + Repo: "https://git.openstack.org/openstack/swift.git", }, }, { "git.openstack.org/openstack/swift/go/hummingbird", - &repoRoot{ + &RepoRoot{ vcs: vcsGit, - repo: "https://git.openstack.org/openstack/swift", + Repo: "https://git.openstack.org/openstack/swift", }, }, { @@ -141,24 +145,28 @@ func TestRepoRootForImportPath(t *testing.T) { nil, }, { + "gitbapache.org", + nil, + }, + { "git.apache.org/package-name.git", - &repoRoot{ + &RepoRoot{ vcs: vcsGit, - repo: "https://git.apache.org/package-name.git", + Repo: "https://git.apache.org/package-name.git", }, }, { "git.apache.org/package-name_2.x.git/path/to/lib", - &repoRoot{ + &RepoRoot{ vcs: vcsGit, - repo: "https://git.apache.org/package-name_2.x.git", + Repo: "https://git.apache.org/package-name_2.x.git", }, }, { "chiselapp.com/user/kyle/repository/fossilgg", - &repoRoot{ + &RepoRoot{ vcs: vcsFossil, - repo: "https://chiselapp.com/user/kyle/repository/fossilgg", + Repo: "https://chiselapp.com/user/kyle/repository/fossilgg", }, }, { @@ -173,21 +181,21 @@ func TestRepoRootForImportPath(t *testing.T) { } for _, test := range tests { - got, err := repoRootForImportPath(test.path, web.Secure) + got, err := RepoRootForImportPath(test.path, IgnoreMod, web.Secure) want := test.want if want == nil { if err == nil { - t.Errorf("repoRootForImportPath(%q): Error expected but not received", test.path) + t.Errorf("RepoRootForImportPath(%q): Error expected but not received", test.path) } continue } if err != nil { - t.Errorf("repoRootForImportPath(%q): %v", test.path, err) + t.Errorf("RepoRootForImportPath(%q): %v", test.path, err) continue } - if got.vcs.name != want.vcs.name || got.repo != want.repo { - t.Errorf("repoRootForImportPath(%q) = VCS(%s) Repo(%s), want VCS(%s) Repo(%s)", test.path, got.vcs, got.repo, want.vcs, want.repo) + if got.vcs.name != want.vcs.name || got.Repo != want.Repo { + t.Errorf("RepoRootForImportPath(%q) = VCS(%s) Repo(%s), want VCS(%s) Repo(%s)", test.path, got.vcs, got.Repo, want.vcs, want.Repo) } } } @@ -219,18 +227,18 @@ func TestFromDir(t *testing.T) { f.Close() } - want := repoRoot{ + want := RepoRoot{ vcs: vcs, - root: path.Join("example.com", vcs.name), + Root: path.Join("example.com", vcs.name), } - var got repoRoot - got.vcs, got.root, err = vcsFromDir(dir, tempDir) + var got RepoRoot + got.vcs, got.Root, err = vcsFromDir(dir, tempDir) if err != nil { t.Errorf("FromDir(%q, %q): %v", dir, tempDir, err) continue } - if got.vcs.name != want.vcs.name || got.root != want.root { - t.Errorf("FromDir(%q, %q) = VCS(%s) Root(%s), want VCS(%s) Root(%s)", dir, tempDir, got.vcs, got.root, want.vcs, want.root) + if got.vcs.name != want.vcs.name || got.Root != want.Root { + t.Errorf("FromDir(%q, %q) = VCS(%s) Root(%s), want VCS(%s) Root(%s)", dir, tempDir, got.vcs, got.Root, want.vcs, want.Root) } } } @@ -393,6 +401,22 @@ func TestMatchGoImport(t *testing.T) { path: "different.example.com/user/foo", err: errors.New("meta tags do not match import path"), }, + { + imports: []metaImport{ + {Prefix: "myitcv.io/blah2", VCS: "mod", RepoRoot: "https://raw.githubusercontent.com/myitcv/pubx/master"}, + {Prefix: "myitcv.io", VCS: "git", RepoRoot: "https://github.com/myitcv/x"}, + }, + path: "myitcv.io/blah2/foo", + mi: metaImport{Prefix: "myitcv.io/blah2", VCS: "mod", RepoRoot: "https://raw.githubusercontent.com/myitcv/pubx/master"}, + }, + { + imports: []metaImport{ + {Prefix: "myitcv.io/blah2", VCS: "mod", RepoRoot: "https://raw.githubusercontent.com/myitcv/pubx/master"}, + {Prefix: "myitcv.io", VCS: "git", RepoRoot: "https://github.com/myitcv/x"}, + }, + path: "myitcv.io/other", + mi: metaImport{Prefix: "myitcv.io", VCS: "git", RepoRoot: "https://github.com/myitcv/x"}, + }, } for _, test := range tests { @@ -409,45 +433,46 @@ func TestMatchGoImport(t *testing.T) { } } -func TestValidateRepoRootScheme(t *testing.T) { +func TestValidateRepoRoot(t *testing.T) { tests := []struct { root string - err string + ok bool }{ { root: "", - err: "no scheme", + ok: false, }, { root: "http://", - err: "", + ok: true, }, { - root: "a://", - err: "", + root: "git+ssh://", + ok: true, }, { - root: "a#://", - err: "invalid scheme", + root: "http#://", + ok: false, + }, + { + root: "-config", + ok: false, }, { root: "-config://", - err: "invalid scheme", + ok: false, }, } for _, test := range tests { - err := validateRepoRootScheme(test.root) - if err == nil { - if test.err != "" { - t.Errorf("validateRepoRootScheme(%q) = nil, want %q", test.root, test.err) - } - } else if test.err == "" { - if err != nil { - t.Errorf("validateRepoRootScheme(%q) = %q, want nil", test.root, test.err) + err := validateRepoRoot(test.root) + ok := err == nil + if ok != test.ok { + want := "error" + if test.ok { + want = "nil" } - } else if err.Error() != test.err { - t.Errorf("validateRepoRootScheme(%q) = %q, want %q", test.root, err, test.err) + t.Errorf("validateRepoRoot(%q) = %q, want %s", test.root, err, want) } } } |