github.com/hustcat/docker@v1.3.3-0.20160314103604-901c67a8eeab/pkg/urlutil/urlutil_test.go (about) 1 package urlutil 2 3 import "testing" 4 5 var ( 6 gitUrls = []string{ 7 "git://github.com/docker/docker", 8 "git@github.com:docker/docker.git", 9 "git@bitbucket.org:atlassianlabs/atlassian-docker.git", 10 "https://github.com/docker/docker.git", 11 "http://github.com/docker/docker.git", 12 "http://github.com/docker/docker.git#branch", 13 "http://github.com/docker/docker.git#:dir", 14 } 15 incompleteGitUrls = []string{ 16 "github.com/docker/docker", 17 } 18 invalidGitUrls = []string{ 19 "http://github.com/docker/docker.git:#branch", 20 } 21 transportUrls = []string{ 22 "tcp://example.com", 23 "tcp+tls://example.com", 24 "udp://example.com", 25 "unix:///example", 26 } 27 ) 28 29 func TestValidGitTransport(t *testing.T) { 30 for _, url := range gitUrls { 31 if IsGitTransport(url) == false { 32 t.Fatalf("%q should be detected as valid Git prefix", url) 33 } 34 } 35 36 for _, url := range incompleteGitUrls { 37 if IsGitTransport(url) == true { 38 t.Fatalf("%q should not be detected as valid Git prefix", url) 39 } 40 } 41 } 42 43 func TestIsGIT(t *testing.T) { 44 for _, url := range gitUrls { 45 if IsGitURL(url) == false { 46 t.Fatalf("%q should be detected as valid Git url", url) 47 } 48 } 49 50 for _, url := range incompleteGitUrls { 51 if IsGitURL(url) == false { 52 t.Fatalf("%q should be detected as valid Git url", url) 53 } 54 } 55 56 for _, url := range invalidGitUrls { 57 if IsGitURL(url) == true { 58 t.Fatalf("%q should not be detected as valid Git prefix", url) 59 } 60 } 61 } 62 63 func TestIsTransport(t *testing.T) { 64 for _, url := range transportUrls { 65 if IsTransportURL(url) == false { 66 t.Fatalf("%q should be detected as valid Transport url", url) 67 } 68 } 69 }