-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflag_constructor_test.go
154 lines (130 loc) · 4.32 KB
/
flag_constructor_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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package flags_test
import (
"github.com/simonleung8/flags"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Flag Constructors", func() {
var (
fc flags.FlagContext
)
BeforeEach(func() {
fc = flags.New()
})
Describe("NewStringFlag()", func() {
It("init the flag context with a new string flagset", func() {
fc.Parse("-s", "test")
Ω(fc.IsSet("s")).To(BeFalse())
Ω(fc.String("s")).To(Equal(""))
fc.NewStringFlag("s", "s2", "setting new string flag")
fc.Parse("-s", "test2")
Ω(fc.IsSet("s")).To(BeTrue())
Ω(fc.IsSet("s2")).To(BeTrue())
Ω(fc.String("s")).To(Equal("test2"))
Ω(fc.String("s2")).To(Equal("test2"))
})
})
Describe("NewStringFlagWithDefault()", func() {
It("init the flag context with a new string flagset with default value", func() {
fc.Parse("-s", "test")
Ω(fc.IsSet("s")).To(BeFalse())
Ω(fc.String("s")).To(Equal(""))
fc.NewStringFlagWithDefault("s", "s2", "setting new string flag", "barz")
fc.Parse()
Ω(fc.IsSet("s")).To(BeTrue())
Ω(fc.IsSet("s2")).To(BeTrue())
Ω(fc.String("s")).To(Equal("barz"))
Ω(fc.String("s2")).To(Equal("barz"))
})
})
Describe("NewBoolFlag()", func() {
It("init the flag context with a new bool flagset", func() {
fc.Parse("--force")
Ω(fc.IsSet("force")).To(BeFalse())
fc.NewBoolFlag("force", "f", "force process")
fc.Parse("--force")
Ω(fc.IsSet("force")).To(BeTrue())
Ω(fc.IsSet("f")).To(BeTrue())
Ω(fc.Bool("force")).To(BeTrue())
Ω(fc.Bool("f")).To(BeTrue())
})
})
Describe("NewIntFlag()", func() {
It("init the flag context with a new int flagset", func() {
fc.Parse("-i", "5")
Ω(fc.IsSet("i")).To(BeFalse())
Ω(fc.Int("i")).To(Equal(0))
fc.NewIntFlag("i", "i2", "setting new int flag")
fc.Parse("-i", "5")
Ω(fc.IsSet("i")).To(BeTrue())
Ω(fc.IsSet("i2")).To(BeTrue())
Ω(fc.Int("i")).To(Equal(5))
Ω(fc.Int("i2")).To(Equal(5))
})
})
Describe("NewIntFlagWithDefault()", func() {
It("init the flag context with a new int flagset with default value", func() {
fc.Parse("-i", "5")
Ω(fc.IsSet("i")).To(BeFalse())
Ω(fc.Int("i")).To(Equal(0))
fc.NewIntFlagWithDefault("i", "i2", "setting new int flag", 10)
fc.Parse()
Ω(fc.IsSet("i")).To(BeTrue())
Ω(fc.IsSet("i2")).To(BeTrue())
Ω(fc.Int("i")).To(Equal(10))
Ω(fc.Int("i2")).To(Equal(10))
})
})
Describe("NewFloat64Flag()", func() {
It("init the flag context with a new float64 flagset", func() {
fc.Parse("-f", "5.5")
Ω(fc.IsSet("f")).To(BeFalse())
Ω(fc.Float64("f")).To(Equal(float64(0)))
fc.NewFloat64Flag("f", "f2", "setting new flag")
fc.Parse("-f", "5.5")
Ω(fc.IsSet("f")).To(BeTrue())
Ω(fc.IsSet("f2")).To(BeTrue())
Ω(fc.Float64("f")).To(Equal(5.5))
Ω(fc.Float64("f2")).To(Equal(5.5))
})
})
Describe("NewFloat64FlagWithDefault()", func() {
It("init the flag context with a new Float64 flagset with default value", func() {
fc.Parse()
Ω(fc.IsSet("i")).To(BeFalse())
Ω(fc.Float64("i")).To(Equal(float64(0)))
fc.NewFloat64FlagWithDefault("i", "i2", "setting new flag", 5.5)
fc.Parse()
Ω(fc.IsSet("i")).To(BeTrue())
Ω(fc.IsSet("i2")).To(BeTrue())
Ω(fc.Float64("i")).To(Equal(5.5))
Ω(fc.Float64("i2")).To(Equal(5.5))
})
})
Describe("NewStringSliceFlag()", func() {
It("init the flag context with a new StringSlice flagset", func() {
fc.Parse("-s", "5", "-s", "6")
Ω(fc.IsSet("s")).To(BeFalse())
Ω(fc.StringSlice("s")).To(Equal([]string{}))
fc.NewStringSliceFlag("s", "s2", "setting new StringSlice flag")
fc.Parse("-s", "5", "-s", "6")
Ω(fc.IsSet("s")).To(BeTrue())
Ω(fc.IsSet("s2")).To(BeTrue())
Ω(fc.StringSlice("s")).To(Equal([]string{"5", "6"}))
Ω(fc.StringSlice("s2")).To(Equal([]string{"5", "6"}))
})
})
Describe("NewStringSliceFlagWithDefault()", func() {
It("init the flag context with a new StringSlice flagset with default value", func() {
fc.Parse()
Ω(fc.IsSet("s")).To(BeFalse())
Ω(fc.StringSlice("s")).To(Equal([]string{}))
fc.NewStringSliceFlagWithDefault("s", "s2", "setting new StringSlice flag", []string{"5", "6", "7"})
fc.Parse()
Ω(fc.IsSet("s")).To(BeTrue())
Ω(fc.IsSet("s2")).To(BeTrue())
Ω(fc.StringSlice("s")).To(Equal([]string{"5", "6", "7"}))
Ω(fc.StringSlice("s2")).To(Equal([]string{"5", "6", "7"}))
})
})
})