Skip to content

Commit

Permalink
Merge pull request #788 from benzvan/master
Browse files Browse the repository at this point in the history
adds test coverage to context
  • Loading branch information
asahasrabuddhe authored Aug 2, 2019
2 parents 693af58 + 6505336 commit 656063a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,18 +253,23 @@ func TestContext_GlobalIsSet_fromEnv(t *testing.T) {
timeoutIsSet, tIsSet bool
noEnvVarIsSet, nIsSet bool
passwordIsSet, pIsSet bool
passwordValue string
unparsableIsSet, uIsSet bool
overrideIsSet, oIsSet bool
overrideValue string
)

clearenv()
os.Setenv("APP_TIMEOUT_SECONDS", "15.5")
os.Setenv("APP_PASSWORD", "")
os.Setenv("APP_PASSWORD", "badpass")
os.Setenv("APP_OVERRIDE", "overridden")
a := App{
Flags: []Flag{
Float64Flag{Name: "timeout, t", EnvVar: "APP_TIMEOUT_SECONDS"},
StringFlag{Name: "password, p", EnvVar: "APP_PASSWORD"},
Float64Flag{Name: "no-env-var, n"},
Float64Flag{Name: "unparsable, u", EnvVar: "APP_UNPARSABLE"},
StringFlag{Name: "overrides-default, o", Value: "default", EnvVar: "APP_OVERRIDE"},
},
Commands: []Command{
{
Expand All @@ -274,10 +279,14 @@ func TestContext_GlobalIsSet_fromEnv(t *testing.T) {
tIsSet = ctx.GlobalIsSet("t")
passwordIsSet = ctx.GlobalIsSet("password")
pIsSet = ctx.GlobalIsSet("p")
passwordValue = ctx.GlobalString("password")
unparsableIsSet = ctx.GlobalIsSet("unparsable")
uIsSet = ctx.GlobalIsSet("u")
noEnvVarIsSet = ctx.GlobalIsSet("no-env-var")
nIsSet = ctx.GlobalIsSet("n")
overrideIsSet = ctx.GlobalIsSet("overrides-default")
oIsSet = ctx.GlobalIsSet("o")
overrideValue = ctx.GlobalString("overrides-default")
return nil
},
},
Expand All @@ -290,8 +299,13 @@ func TestContext_GlobalIsSet_fromEnv(t *testing.T) {
expect(t, tIsSet, true)
expect(t, passwordIsSet, true)
expect(t, pIsSet, true)
expect(t, passwordValue, "badpass")
expect(t, unparsableIsSet, false)
expect(t, noEnvVarIsSet, false)
expect(t, nIsSet, false)
expect(t, overrideIsSet, true)
expect(t, oIsSet, true)
expect(t, overrideValue, "overridden")

os.Setenv("APP_UNPARSABLE", "foobar")
if err := a.Run([]string{"run"}); err != nil {
Expand Down

0 comments on commit 656063a

Please sign in to comment.