MCPcopy
hub / github.com/urfave/cli / TestFlagsFromEnv

Function TestFlagsFromEnv

flag_test.go:156–456  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

154}
155
156func TestFlagsFromEnv(t *testing.T) {
157 testCases := []struct {
158 name string
159 input string
160 output any
161 fl Flag
162 errContains string
163 }{
164 {
165 name: "BoolFlag valid true",
166 input: "1",
167 output: true,
168 fl: &BoolFlag{Name: "debug", Sources: EnvVars("DEBUG")},
169 },
170 {
171 name: "BoolFlag valid false",
172 input: "false",
173 output: false,
174 fl: &BoolFlag{Name: "debug", Sources: EnvVars("DEBUG")},
175 },
176 {
177 name: "BoolFlag invalid",
178 input: "foobar",
179 output: true,
180 fl: &BoolFlag{Name: "debug", Sources: EnvVars("DEBUG")},
181 errContains: `could not parse "foobar" as bool value from environment variable ` +
182 `"DEBUG" for flag debug:`,
183 },
184 {
185 name: "BoolInverse Empty",
186 output: false,
187 fl: &BoolWithInverseFlag{Name: "debug", Sources: EnvVars("DEBUG")},
188 },
189 {
190 name: "DurationFlag valid",
191 input: "1s",
192 output: 1 * time.Second,
193 fl: &DurationFlag{Name: "time", Sources: EnvVars("TIME")},
194 },
195 {
196 name: "DurationFlag invalid",
197 input: "foobar",
198 output: false,
199 fl: &DurationFlag{Name: "time", Sources: EnvVars("TIME")},
200 errContains: `could not parse "foobar" as time.Duration value from environment ` +
201 `variable "TIME" for flag time:`,
202 },
203
204 {
205 name: "Float64Flag valid",
206 input: "1.2",
207 output: 1.2,
208 fl: &FloatFlag{Name: "seconds", Sources: EnvVars("SECONDS")},
209 },
210 {
211 name: "Float64Flag valid from int",
212 input: "1",
213 output: 1.0,

Callers

nothing calls this directly

Calls 8

RunMethod · 0.95
ValueMethod · 0.95
FlagNamesMethod · 0.95
EnvVarsFunction · 0.85
buildTestContextFunction · 0.85
GetEnvVarsMethod · 0.65
NamesMethod · 0.65
IsSetMethod · 0.65

Tested by

no test coverage detected