-
Notifications
You must be signed in to change notification settings - Fork 8
/
url_test.go
52 lines (38 loc) · 1.3 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
package flag_test
import (
"github.com/concourse/flag/v2"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("URLFlag", func() {
It("strips slashes from the end of urls", func() {
flag := flag.URL{}
err := flag.UnmarshalFlag("http://example.com/")
Expect(err).ToNot(HaveOccurred())
Expect(flag.String()).To(Equal("http://example.com"))
})
It("doesn't strip anything from urls with no slashes", func() {
flag := flag.URL{}
err := flag.UnmarshalFlag("https://example.com")
Expect(err).ToNot(HaveOccurred())
Expect(flag.String()).To(Equal("https://example.com"))
})
It("returns an error when a scheme is not specified", func() {
flag := flag.URL{}
err := flag.UnmarshalFlag("example.com/")
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("missing scheme in 'example.com'"))
})
It("returns an error for localhost without scheme", func() {
flag := flag.URL{}
err := flag.UnmarshalFlag("localhost:8080")
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("missing scheme in 'localhost:8080'"))
})
It("unmarshalls localhost with scheme correctly", func() {
flag := flag.URL{}
err := flag.UnmarshalFlag("http://localhost:8080")
Expect(err).ToNot(HaveOccurred())
Expect(flag.String()).To(Equal("http://localhost:8080"))
})
})