leaks_test.go 922 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package main
  2. import "testing"
  3. func TestGetLocalRepoName(t *testing.T) {
  4. cases := []struct {
  5. name string
  6. input string
  7. expected string
  8. }{
  9. {
  10. "Usual github url",
  11. "https://github.com/usual/url",
  12. "url",
  13. },
  14. {
  15. "Usual github url with .git suffix",
  16. "https://github.com/usual/url.git",
  17. "url",
  18. },
  19. {
  20. "personal git url",
  21. "git@github.com:url.git",
  22. "url",
  23. },
  24. {
  25. "personal git url in sub folder",
  26. "git@github.com:sub/url.git",
  27. "url",
  28. },
  29. {
  30. "ssh git url with port",
  31. "ssh://git@github.com:2222/sub/url.git",
  32. "url",
  33. },
  34. {
  35. "local git in sub folder",
  36. "local/url.git",
  37. "url",
  38. },
  39. {
  40. "local git in same folder",
  41. "url.git",
  42. "url",
  43. },
  44. }
  45. for _, c := range cases {
  46. actual := getLocalRepoName(c.input)
  47. if actual != c.expected {
  48. t.Errorf("'%s' failed. Input: '%s'; Expected: '%s'; Got: '%s'", c.input, c.name, c.expected, actual)
  49. }
  50. }
  51. }