diff --git a/uaa_internals_test.go b/uaa_internals_test.go index fc19a83..af8907c 100644 --- a/uaa_internals_test.go +++ b/uaa_internals_test.go @@ -13,8 +13,9 @@ func init() { suite = spec.New("uaa-internals", spec.Report(report.Terminal{})) suite("ensureTransport", testEnsureTransport) suite("contains", testContains) + suite("URLWithPath", testURLWithPath) } func TestUAAInternals(t *testing.T) { suite.Run(t) -} \ No newline at end of file +} diff --git a/url.go b/url.go index 8486f22..037aa3c 100644 --- a/url.go +++ b/url.go @@ -3,6 +3,7 @@ package uaa import ( "fmt" "net/url" + "path" "strings" ) @@ -32,7 +33,7 @@ func BuildSubdomainURL(target string, zoneID string) (*url.URL, error) { } // urlWithPath copies the URL and sets the path on the copy. -func urlWithPath(u url.URL, path string) url.URL { - u.Path = path +func urlWithPath(u url.URL, p string) url.URL { + u.Path = path.Join(u.Path, p) return u } diff --git a/url_internal_test.go b/url_internal_test.go new file mode 100644 index 0000000..1a3a563 --- /dev/null +++ b/url_internal_test.go @@ -0,0 +1,26 @@ +package uaa + +import ( + "log" + "net/url" + "testing" + + . "github.com/onsi/gomega" + "github.com/sclevine/spec" +) + +func testURLWithPath(t *testing.T, when spec.G, it spec.S) { + it.Before(func() { + RegisterTestingT(t) + log.SetFlags(log.Lshortfile) + }) + + it("returns a URL which retains the path", func() { + url, err := url.Parse("http://example.com/uaa") + Expect(url).NotTo(BeNil()) + Expect(err).To(BeNil()) + + withPath := urlWithPath(*url, "path") + Expect(withPath.String()).To(Equal("http://example.com/uaa/path")) + }) +}