url_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package util
  2. import (
  3. "testing"
  4. . "github.com/smartystreets/goconvey/convey"
  5. )
  6. func TestUrl(t *testing.T) {
  7. Convey("When joining two urls where right hand side is empty", t, func() {
  8. result := JoinUrlFragments("http://localhost:8080", "")
  9. So(result, ShouldEqual, "http://localhost:8080")
  10. })
  11. Convey("When joining two urls where right hand side is empty and lefthand side has a trailing slash", t, func() {
  12. result := JoinUrlFragments("http://localhost:8080/", "")
  13. So(result, ShouldEqual, "http://localhost:8080/")
  14. })
  15. Convey("When joining two urls where neither has a trailing slash", t, func() {
  16. result := JoinUrlFragments("http://localhost:8080", "api")
  17. So(result, ShouldEqual, "http://localhost:8080/api")
  18. })
  19. Convey("When joining two urls where lefthand side has a trailing slash", t, func() {
  20. result := JoinUrlFragments("http://localhost:8080/", "api")
  21. So(result, ShouldEqual, "http://localhost:8080/api")
  22. })
  23. Convey("When joining two urls where righthand side has preceding slash", t, func() {
  24. result := JoinUrlFragments("http://localhost:8080", "/api")
  25. So(result, ShouldEqual, "http://localhost:8080/api")
  26. })
  27. Convey("When joining two urls where righthand side has trailing slash", t, func() {
  28. result := JoinUrlFragments("http://localhost:8080", "api/")
  29. So(result, ShouldEqual, "http://localhost:8080/api/")
  30. })
  31. }