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