urlutil_test.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 TestValidGitTransport(t *testing.T) {
  28. for _, url := range gitUrls {
  29. if !IsGitTransport(url) {
  30. t.Fatalf("%q should be detected as valid Git prefix", url)
  31. }
  32. }
  33. for _, url := range incompleteGitUrls {
  34. if IsGitTransport(url) {
  35. t.Fatalf("%q should not be detected as valid Git prefix", url)
  36. }
  37. }
  38. }
  39. func TestIsGIT(t *testing.T) {
  40. for _, url := range gitUrls {
  41. if !IsGitURL(url) {
  42. t.Fatalf("%q should be detected as valid Git url", url)
  43. }
  44. }
  45. for _, url := range incompleteGitUrls {
  46. if !IsGitURL(url) {
  47. t.Fatalf("%q should be detected as valid Git url", url)
  48. }
  49. }
  50. for _, url := range invalidGitUrls {
  51. if IsGitURL(url) {
  52. t.Fatalf("%q should not be detected as valid Git prefix", url)
  53. }
  54. }
  55. }
  56. func TestIsTransport(t *testing.T) {
  57. for _, url := range transportUrls {
  58. if !IsTransportURL(url) {
  59. t.Fatalf("%q should be detected as valid Transport url", url)
  60. }
  61. }
  62. }