2018-02-05 21:05:59 +00:00
|
|
|
package urlutil // import "github.com/docker/docker/pkg/urlutil"
|
2014-11-24 23:10:37 +00:00
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
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",
|
2015-04-24 22:12:45 +00:00
|
|
|
"http://github.com/docker/docker.git#branch",
|
|
|
|
"http://github.com/docker/docker.git#:dir",
|
2014-11-24 23:10:37 +00:00
|
|
|
}
|
|
|
|
incompleteGitUrls = []string{
|
|
|
|
"github.com/docker/docker",
|
|
|
|
}
|
2015-04-24 22:12:45 +00:00
|
|
|
invalidGitUrls = []string{
|
|
|
|
"http://github.com/docker/docker.git:#branch",
|
|
|
|
}
|
2016-02-08 17:29:01 +00:00
|
|
|
transportUrls = []string{
|
|
|
|
"tcp://example.com",
|
|
|
|
"tcp+tls://example.com",
|
|
|
|
"udp://example.com",
|
|
|
|
"unix:///example",
|
2016-03-29 10:21:41 +00:00
|
|
|
"unixgram:///example",
|
2016-02-08 17:29:01 +00:00
|
|
|
}
|
2014-11-24 23:10:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestIsGIT(t *testing.T) {
|
|
|
|
for _, url := range gitUrls {
|
2017-03-30 09:16:48 +00:00
|
|
|
if !IsGitURL(url) {
|
2014-11-24 23:10:37 +00:00
|
|
|
t.Fatalf("%q should be detected as valid Git url", url)
|
|
|
|
}
|
|
|
|
}
|
2015-04-24 22:12:45 +00:00
|
|
|
|
2014-11-24 23:10:37 +00:00
|
|
|
for _, url := range incompleteGitUrls {
|
2017-03-30 09:16:48 +00:00
|
|
|
if !IsGitURL(url) {
|
2014-11-24 23:10:37 +00:00
|
|
|
t.Fatalf("%q should be detected as valid Git url", url)
|
|
|
|
}
|
|
|
|
}
|
2015-04-24 22:12:45 +00:00
|
|
|
|
|
|
|
for _, url := range invalidGitUrls {
|
2017-03-30 09:16:48 +00:00
|
|
|
if IsGitURL(url) {
|
2015-04-24 22:12:45 +00:00
|
|
|
t.Fatalf("%q should not be detected as valid Git prefix", url)
|
|
|
|
}
|
|
|
|
}
|
2014-11-24 23:10:37 +00:00
|
|
|
}
|
2016-02-08 17:29:01 +00:00
|
|
|
|
|
|
|
func TestIsTransport(t *testing.T) {
|
|
|
|
for _, url := range transportUrls {
|
2017-03-30 09:16:48 +00:00
|
|
|
if !IsTransportURL(url) {
|
2016-02-08 17:29:01 +00:00
|
|
|
t.Fatalf("%q should be detected as valid Transport url", url)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|