Move git and url checks into pkg

This moves the IsGIT and IsURL functions out of the generic `utils`
package and into their own `urlutil` pkg.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby
2014-11-24 18:10:37 -05:00
parent df7c22dd23
commit feca1b1780
5 changed files with 93 additions and 55 deletions
+1 -15
View File
@@ -288,21 +288,7 @@ func NewHTTPRequestError(msg string, res *http.Response) error {
}
}
func IsURL(str string) bool {
return strings.HasPrefix(str, "http://") || strings.HasPrefix(str, "https://")
}
func IsGIT(str string) bool {
return strings.HasPrefix(str, "git://") || strings.HasPrefix(str, "github.com/") || strings.HasPrefix(str, "git@") || (strings.HasSuffix(str, ".git") && IsURL(str))
}
func ValidGitTransport(str string) bool {
return strings.HasPrefix(str, "git://") || strings.HasPrefix(str, "git@") || IsURL(str)
}
var (
localHostRx = regexp.MustCompile(`(?m)^nameserver 127[^\n]+\n*`)
)
var localHostRx = regexp.MustCompile(`(?m)^nameserver 127[^\n]+\n*`)
// RemoveLocalDns looks into the /etc/resolv.conf,
// and removes any local nameserver entries.
-40
View File
@@ -97,43 +97,3 @@ func TestReadSymlinkedDirectoryToFile(t *testing.T) {
t.Errorf("failed to remove symlink: %s", err)
}
}
var (
gitUrls = []string{
"git://github.com/docker/docker",
"git@github.com:docker/docker.git",
"git@bitbucket.org:atlassianlabs/atlassian-docker.git",
"https://github.com/docker/docker.git",
"http://github.com/docker/docker.git",
}
incompleteGitUrls = []string{
"github.com/docker/docker",
}
)
func TestValidGitTransport(t *testing.T) {
for _, url := range gitUrls {
if ValidGitTransport(url) == false {
t.Fatalf("%q should be detected as valid Git prefix", url)
}
}
for _, url := range incompleteGitUrls {
if ValidGitTransport(url) == true {
t.Fatalf("%q should not be detected as valid Git prefix", url)
}
}
}
func TestIsGIT(t *testing.T) {
for _, url := range gitUrls {
if IsGIT(url) == false {
t.Fatalf("%q should be detected as valid Git url", url)
}
}
for _, url := range incompleteGitUrls {
if IsGIT(url) == false {
t.Fatalf("%q should be detected as valid Git url", url)
}
}
}