Skip to content

Commit

Permalink
Merge pull request #19 from shamus/chores/target-url-maintains-path
Browse files Browse the repository at this point in the history
Maintain target url path.
  • Loading branch information
joefitzgerald authored Jun 19, 2019
2 parents 17ea8b9 + 153e485 commit d58dea9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
3 changes: 2 additions & 1 deletion uaa_internals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
5 changes: 3 additions & 2 deletions url.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package uaa
import (
"fmt"
"net/url"
"path"
"strings"
)

Expand Down Expand Up @@ -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
}
26 changes: 26 additions & 0 deletions url_internal_test.go
Original file line number Diff line number Diff line change
@@ -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"))
})
}

0 comments on commit d58dea9

Please sign in to comment.