git_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. )
  20. func TestValidGitTransport(t *testing.T) {
  21. for _, url := range gitUrls {
  22. if IsGitTransport(url) == false {
  23. t.Fatalf("%q should be detected as valid Git prefix", url)
  24. }
  25. }
  26. for _, url := range incompleteGitUrls {
  27. if IsGitTransport(url) == true {
  28. t.Fatalf("%q should not be detected as valid Git prefix", url)
  29. }
  30. }
  31. }
  32. func TestIsGIT(t *testing.T) {
  33. for _, url := range gitUrls {
  34. if IsGitURL(url) == false {
  35. t.Fatalf("%q should be detected as valid Git url", url)
  36. }
  37. }
  38. for _, url := range incompleteGitUrls {
  39. if IsGitURL(url) == false {
  40. t.Fatalf("%q should be detected as valid Git url", url)
  41. }
  42. }
  43. for _, url := range invalidGitUrls {
  44. if IsGitURL(url) == true {
  45. t.Fatalf("%q should not be detected as valid Git prefix", url)
  46. }
  47. }
  48. }