forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathport_test.go
56 lines (50 loc) · 1.57 KB
/
port_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 flag_test
import (
. "code.cloudfoundry.org/cli/command/flag"
"code.cloudfoundry.org/cli/types"
flags "github.com/jessevdk/go-flags"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Port", func() {
var port Port
BeforeEach(func() {
port = Port{}
})
Describe("UnmarshalFlag", func() {
When("the empty string is provided", func() {
It("sets IsSet to false", func() {
err := port.UnmarshalFlag("")
Expect(err).ToNot(HaveOccurred())
Expect(port).To(Equal(Port{NullInt: types.NullInt{Value: 0, IsSet: false}}))
})
})
When("an invalid integer is provided", func() {
It("returns an error", func() {
err := port.IsValidValue("abcdef")
Expect(err).To(MatchError(&flags.Error{
Type: flags.ErrRequired,
Message: "invalid argument for flag '--port' (expected int > 0)",
}))
Expect(port).To(Equal(Port{NullInt: types.NullInt{Value: 0, IsSet: false}}))
})
})
When("a negative integer is provided", func() {
It("returns an error", func() {
err := port.IsValidValue("-10")
Expect(err).To(MatchError(&flags.Error{
Type: flags.ErrRequired,
Message: "invalid argument for flag '--port' (expected int > 0)",
}))
Expect(port).To(Equal(Port{NullInt: types.NullInt{Value: -10, IsSet: true}}))
})
})
When("a valid integer is provided", func() {
It("stores the integer and sets IsSet to true", func() {
err := port.IsValidValue("0")
Expect(err).ToNot(HaveOccurred())
Expect(port).To(Equal(Port{NullInt: types.NullInt{Value: 0, IsSet: true}}))
})
})
})
})