-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathurl_test.go
56 lines (49 loc) · 1.52 KB
/
url_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package uaa_test
import (
"log"
"testing"
uaa "github.com/cloudfoundry-community/go-uaa"
. "github.com/onsi/gomega"
"github.com/sclevine/spec"
)
func testBuildSubdomainURL(t *testing.T, when spec.G, it spec.S) {
it.Before(func() {
RegisterTestingT(t)
log.SetFlags(log.Lshortfile)
})
it("returns a URL", func() {
url, err := uaa.BuildSubdomainURL("http://test.example.com", "")
Expect(err).NotTo(HaveOccurred())
Expect(url).NotTo(BeNil())
Expect(url.String()).To(Equal("http://test.example.com"))
})
it("returns an error when the url is invalid", func() {
url, err := uaa.BuildSubdomainURL("(*#&^@%$&%)", "")
Expect(err).To(HaveOccurred())
Expect(url).To(BeNil())
})
when("the zone ID is set", func() {
it("adds the zone ID as a prefix to the target", func() {
testCases := []struct {
target string
zoneID string
expected string
}{
{"http://test.example.com", "zone1", "http://zone1.test.example.com"},
{"https://test.example.com", "zone1", "https://zone1.test.example.com"},
{"test.example.com", "zone1", "https://zone1.test.example.com"},
}
for i := range testCases {
url, err := uaa.BuildSubdomainURL(testCases[i].target, testCases[i].zoneID)
Expect(err).NotTo(HaveOccurred())
Expect(url).NotTo(BeNil())
Expect(url.String()).To(Equal(testCases[i].expected))
}
})
it("returns an error when the url is invalid", func() {
url, err := uaa.BuildSubdomainURL("(*#&^@%$&%)", "zone1")
Expect(err).To(HaveOccurred())
Expect(url).To(BeNil())
})
})
}