Skip to content

Commit

Permalink
Remove Unsetenv because it was added in a more recent version of go a…
Browse files Browse the repository at this point in the history
…nd add missing with envar error test case
  • Loading branch information
Gordon Goetz committed Mar 15, 2016
1 parent 62df01d commit a1b275e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 11 additions & 6 deletions args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,27 @@ func TestArgMultipleValuesDefault(t *testing.T) {
assert.Equal(t, []string{"default1", "default2"}, *a)
}

func TestRequiredArgWithEnvarMissingErrors(t *testing.T) {
app := newTestApp()
app.Arg("t", "").Envar("TEST_ARG_ENVAR").Required().Int()
_, err := app.Parse([]string{})
assert.Error(t, err)
}

func TestArgRequiredWithEnvar(t *testing.T) {
os.Setenv("TEST_ENVAR", "123")
defer os.Unsetenv("TEST_ENVAR")
os.Setenv("TEST_ARG_ENVAR", "123")
app := newTestApp()
flag := app.Arg("t", "").Envar("TEST_ENVAR").Required().Int()
flag := app.Arg("t", "").Envar("TEST_ARG_ENVAR").Required().Int()
_, err := app.Parse([]string{})
assert.NoError(t, err)
assert.Equal(t, 123, *flag)
}

func TestSubcommandArgRequiredWithEnvar(t *testing.T) {
os.Setenv("TEST_ENVAR", "123")
defer os.Unsetenv("TEST_ENVAR")
os.Setenv("TEST_ARG_ENVAR", "123")
app := newTestApp()
cmd := app.Command("command", "")
flag := cmd.Arg("t", "").Envar("TEST_ENVAR").Required().Int()
flag := cmd.Arg("t", "").Envar("TEST_ARG_ENVAR").Required().Int()
_, err := app.Parse([]string{"command"})
assert.NoError(t, err)
assert.Equal(t, 123, *flag)
Expand Down
2 changes: 0 additions & 2 deletions flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ func TestRequiredWithEnvarMissingErrors(t *testing.T) {

func TestRequiredWithEnvar(t *testing.T) {
os.Setenv("TEST_ENVAR", "123")
defer os.Unsetenv("TEST_ENVAR")
app := newTestApp()
flag := app.Flag("t", "").Envar("TEST_ENVAR").Required().Int()
_, err := app.Parse([]string{})
Expand All @@ -111,7 +110,6 @@ func TestRequiredWithEnvar(t *testing.T) {

func TestSubcommandFlagRequiredWithEnvar(t *testing.T) {
os.Setenv("TEST_ENVAR", "123")
defer os.Unsetenv("TEST_ENVAR")
app := newTestApp()
cmd := app.Command("command", "")
flag := cmd.Flag("t", "").Envar("TEST_ENVAR").Required().Int()
Expand Down

0 comments on commit a1b275e

Please sign in to comment.