mirror of
https://github.com/clearlinux/docker.git
synced 2026-09-06 05:31:47 +00:00
Add HasValidGITPrefix to utils/utils.go
This will allow us to use a common Git prefix check for both api/clients/commands.go and builder/job.go. Previous prefix check in build from Git (in builder/jobs.go) ignored valid prefixes such as "git@", "http://" or "https://". Signed-off-by: Lakshan Perera <lakshan@laktek.com>
This commit is contained in:
@@ -304,6 +304,10 @@ func IsGIT(str string) bool {
|
||||
return strings.HasPrefix(str, "git://") || strings.HasPrefix(str, "github.com/") || strings.HasPrefix(str, "git@github.com:") || (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*`)
|
||||
)
|
||||
|
||||
@@ -97,3 +97,24 @@ func TestReadSymlinkedDirectoryToFile(t *testing.T) {
|
||||
t.Errorf("failed to remove symlink: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidGitTransport(t *testing.T) {
|
||||
for _, url := range []string{
|
||||
"git://github.com/docker/docker",
|
||||
"git@github.com:docker/docker.git",
|
||||
"https://github.com/docker/docker.git",
|
||||
"http://github.com/docker/docker.git",
|
||||
} {
|
||||
if ValidGitTransport(url) == false {
|
||||
t.Fatalf("%q should be detected as valid Git prefix", url)
|
||||
}
|
||||
}
|
||||
|
||||
for _, url := range []string{
|
||||
"github.com/docker/docker",
|
||||
} {
|
||||
if ValidGitTransport(url) == true {
|
||||
t.Fatalf("%q should not be detected as valid Git prefix", url)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user