github.com/miolini/go@v0.0.0-20160405192216-fca68c8cb408/src/cmd/go/vcs_test.go (about) 1 // Copyright 2014 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "internal/testenv" 9 "testing" 10 ) 11 12 // Test that RepoRootForImportPath creates the correct RepoRoot for a given importPath. 13 // TODO(cmang): Add tests for SVN and BZR. 14 func TestRepoRootForImportPath(t *testing.T) { 15 testenv.MustHaveExternalNetwork(t) 16 17 tests := []struct { 18 path string 19 want *repoRoot 20 }{ 21 { 22 "github.com/golang/groupcache", 23 &repoRoot{ 24 vcs: vcsGit, 25 repo: "https://github.com/golang/groupcache", 26 }, 27 }, 28 // IBM DevOps Services tests 29 { 30 "hub.jazz.net/git/user1/pkgname", 31 &repoRoot{ 32 vcs: vcsGit, 33 repo: "https://hub.jazz.net/git/user1/pkgname", 34 }, 35 }, 36 { 37 "hub.jazz.net/git/user1/pkgname/submodule/submodule/submodule", 38 &repoRoot{ 39 vcs: vcsGit, 40 repo: "https://hub.jazz.net/git/user1/pkgname", 41 }, 42 }, 43 { 44 "hub.jazz.net", 45 nil, 46 }, 47 { 48 "hub2.jazz.net", 49 nil, 50 }, 51 { 52 "hub.jazz.net/someotherprefix", 53 nil, 54 }, 55 { 56 "hub.jazz.net/someotherprefix/user1/pkgname", 57 nil, 58 }, 59 // Spaces are not valid in user names or package names 60 { 61 "hub.jazz.net/git/User 1/pkgname", 62 nil, 63 }, 64 { 65 "hub.jazz.net/git/user1/pkg name", 66 nil, 67 }, 68 // Dots are not valid in user names 69 { 70 "hub.jazz.net/git/user.1/pkgname", 71 nil, 72 }, 73 { 74 "hub.jazz.net/git/user/pkg.name", 75 &repoRoot{ 76 vcs: vcsGit, 77 repo: "https://hub.jazz.net/git/user/pkg.name", 78 }, 79 }, 80 // User names cannot have uppercase letters 81 { 82 "hub.jazz.net/git/USER/pkgname", 83 nil, 84 }, 85 // Spaces are not valid in package name 86 { 87 "git.apache.org/package name/path/to/lib", 88 nil, 89 }, 90 // Should have ".git" suffix 91 { 92 "git.apache.org/package-name/path/to/lib", 93 nil, 94 }, 95 { 96 "git.apache.org/package-name.git", 97 &repoRoot{ 98 vcs: vcsGit, 99 repo: "https://git.apache.org/package-name.git", 100 }, 101 }, 102 { 103 "git.apache.org/package-name_2.x.git/path/to/lib", 104 &repoRoot{ 105 vcs: vcsGit, 106 repo: "https://git.apache.org/package-name_2.x.git", 107 }, 108 }, 109 } 110 111 for _, test := range tests { 112 got, err := repoRootForImportPath(test.path, secure) 113 want := test.want 114 115 if want == nil { 116 if err == nil { 117 t.Errorf("RepoRootForImport(%q): Error expected but not received", test.path) 118 } 119 continue 120 } 121 if err != nil { 122 t.Errorf("RepoRootForImport(%q): %v", test.path, err) 123 continue 124 } 125 if got.vcs.name != want.vcs.name || got.repo != want.repo { 126 t.Errorf("RepoRootForImport(%q) = VCS(%s) Repo(%s), want VCS(%s) Repo(%s)", test.path, got.vcs, got.repo, want.vcs, want.repo) 127 } 128 } 129 } 130 131 func TestIsSecure(t *testing.T) { 132 tests := []struct { 133 vcs *vcsCmd 134 url string 135 secure bool 136 }{ 137 {vcsGit, "http://example.com/foo.git", false}, 138 {vcsGit, "https://example.com/foo.git", true}, 139 {vcsBzr, "http://example.com/foo.bzr", false}, 140 {vcsBzr, "https://example.com/foo.bzr", true}, 141 {vcsSvn, "http://example.com/svn", false}, 142 {vcsSvn, "https://example.com/svn", true}, 143 {vcsHg, "http://example.com/foo.hg", false}, 144 {vcsHg, "https://example.com/foo.hg", true}, 145 {vcsGit, "ssh://user@example.com/foo.git", true}, 146 {vcsGit, "user@server:path/to/repo.git", false}, 147 {vcsGit, "user@server:", false}, 148 {vcsGit, "server:repo.git", false}, 149 {vcsGit, "server:path/to/repo.git", false}, 150 {vcsGit, "example.com:path/to/repo.git", false}, 151 {vcsGit, "path/that/contains/a:colon/repo.git", false}, 152 {vcsHg, "ssh://user@example.com/path/to/repo.hg", true}, 153 } 154 155 for _, test := range tests { 156 secure := test.vcs.isSecure(test.url) 157 if secure != test.secure { 158 t.Errorf("%s isSecure(%q) = %t; want %t", test.vcs, test.url, secure, test.secure) 159 } 160 } 161 }