urlutil_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package urlutil
  2. import "testing"
  3. var (
  4. gitUrls = []string{
  5. "git://github.com/docker/docker",
  6. "git@github.com:docker/docker.git",
  7. "git@bitbucket.org:atlassianlabs/atlassian-docker.git",
  8. "https://github.com/docker/docker.git",
  9. "http://github.com/docker/docker.git",
  10. "http://github.com/docker/docker.git#branch",
  11. "http://github.com/docker/docker.git#:dir",
  12. }
  13. incompleteGitUrls = []string{
  14. "github.com/docker/docker",
  15. }
  16. invalidGitUrls = []string{
  17. "http://github.com/docker/docker.git:#branch",
  18. }
  19. transportUrls = []string{
  20. "tcp://example.com",
  21. "tcp+tls://example.com",
  22. "udp://example.com",
  23. "unix:///example",
  24. "unixgram:///example",
  25. }
  26. )
  27. func TestIsGIT(t *testing.T) {
  28. for _, url := range gitUrls {
  29. if !IsGitURL(url) {
  30. t.Fatalf("%q should be detected as valid Git url", url)
  31. }
  32. }
  33. for _, url := range incompleteGitUrls {
  34. if !IsGitURL(url) {
  35. t.Fatalf("%q should be detected as valid Git url", url)
  36. }
  37. }
  38. for _, url := range invalidGitUrls {
  39. if IsGitURL(url) {
  40. t.Fatalf("%q should not be detected as valid Git prefix", url)
  41. }
  42. }
  43. }
  44. func TestIsTransport(t *testing.T) {
  45. for _, url := range transportUrls {
  46. if !IsTransportURL(url) {
  47. t.Fatalf("%q should be detected as valid Transport url", url)
  48. }
  49. }
  50. }