You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.6 KiB

  1. package urls
  2. import (
  3. "testing"
  4. )
  5. var urltests = []struct {
  6. in string
  7. outBase string
  8. outKey string
  9. outRaw string
  10. }{
  11. // valid url key as input
  12. {"matrix.org/jira", "https://matrix.org/jira/", "matrix.org/jira", "matrix.org/jira"},
  13. // valid url base as input
  14. {"https://matrix.org/jira/", "https://matrix.org/jira/", "matrix.org/jira", "https://matrix.org/jira/"},
  15. // valid rest url as input
  16. {"https://matrix.org/jira/rest/api/2/issue/12680", "https://matrix.org/jira/", "matrix.org/jira", "https://matrix.org/jira/rest/api/2/issue/12680"},
  17. // missing trailing slash as input
  18. {"https://matrix.org/jira", "https://matrix.org/jira/", "matrix.org/jira", "https://matrix.org/jira"},
  19. // missing protocol but with trailing slash
  20. {"matrix.org/jira/", "https://matrix.org/jira/", "matrix.org/jira", "matrix.org/jira/"},
  21. // no jira path as base url (subdomain)
  22. {"https://jira.matrix.org", "https://jira.matrix.org/", "jira.matrix.org", "https://jira.matrix.org"},
  23. // explicit http as input
  24. {"http://matrix.org/jira", "http://matrix.org/jira/", "matrix.org/jira", "http://matrix.org/jira"},
  25. }
  26. func TestParseJIRAURL(t *testing.T) {
  27. for _, urltest := range urltests {
  28. jURL, err := ParseJIRAURL(urltest.in)
  29. if err != nil {
  30. t.Fatal(err)
  31. }
  32. if jURL.Key != urltest.outKey {
  33. t.Fatalf("ParseJIRAURL(%s) => Key: Want %s got %s", urltest.in, urltest.outKey, jURL.Key)
  34. }
  35. if jURL.Base != urltest.outBase {
  36. t.Fatalf("ParseJIRAURL(%s) => Base: Want %s got %s", urltest.in, urltest.outBase, jURL.Base)
  37. }
  38. if jURL.Raw != urltest.outRaw {
  39. t.Fatalf("ParseJIRAURL(%s) => Raw: Want %s got %s", urltest.in, urltest.outRaw, jURL.Raw)
  40. }
  41. }
  42. }