update test to reflect app flag usage
This commit is contained in:
parent
714a73f028
commit
95d3a8624d
21
app_test.go
21
app_test.go
@ -880,7 +880,7 @@ func TestAppNoHelpFlag(t *testing.T) {
|
|||||||
func TestRequiredFlagAppRunBehavior(t *testing.T) {
|
func TestRequiredFlagAppRunBehavior(t *testing.T) {
|
||||||
tdata := []struct {
|
tdata := []struct {
|
||||||
testCase string
|
testCase string
|
||||||
flags []Flag
|
appFlags []Flag
|
||||||
appRunInput []string
|
appRunInput []string
|
||||||
expectedAnError bool
|
expectedAnError bool
|
||||||
}{
|
}{
|
||||||
@ -889,8 +889,8 @@ func TestRequiredFlagAppRunBehavior(t *testing.T) {
|
|||||||
// - empty input, when a required flag is present, shows the help message
|
// - empty input, when a required flag is present, shows the help message
|
||||||
// - empty input, when a required flag is present, errors and shows the flag error message
|
// - empty input, when a required flag is present, errors and shows the flag error message
|
||||||
testCase: "empty_input_with_required_flag",
|
testCase: "empty_input_with_required_flag",
|
||||||
appRunInput: []string{"command"},
|
appRunInput: []string{"myCLI"},
|
||||||
flags: []Flag{StringFlag{Name: "requiredFlag", Required: true}},
|
appFlags: []Flag{StringFlag{Name: "requiredFlag", Required: true}},
|
||||||
expectedAnError: true,
|
expectedAnError: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -898,18 +898,23 @@ func TestRequiredFlagAppRunBehavior(t *testing.T) {
|
|||||||
// - inputing --help, when a required flag is present, shows the help message
|
// - inputing --help, when a required flag is present, shows the help message
|
||||||
// - inputing --help, when a required flag is present, does not error
|
// - inputing --help, when a required flag is present, does not error
|
||||||
testCase: "help_input_with_required_flag",
|
testCase: "help_input_with_required_flag",
|
||||||
appRunInput: []string{"command", "--help"},
|
appRunInput: []string{"myCLI", "--help"},
|
||||||
flags: []Flag{StringFlag{Name: "requiredFlag", Required: true}},
|
appFlags: []Flag{StringFlag{Name: "requiredFlag", Required: true}},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// expectations:
|
// expectations:
|
||||||
// - giving optional input, when a required flag is present, shows the help message
|
// - giving optional input, when a required flag is present, shows the help message
|
||||||
// - giving optional input, when a required flag is present, errors and shows the flag error message
|
// - giving optional input, when a required flag is present, errors and shows the flag error message
|
||||||
testCase: "optional_input_with_required_flag",
|
testCase: "optional_input_with_required_flag",
|
||||||
appRunInput: []string{"command", "--optional", "cats"},
|
appRunInput: []string{"myCLI", "--optional", "cats"},
|
||||||
flags: []Flag{StringFlag{Name: "requiredFlag", Required: true}, StringFlag{Name: "optional"}},
|
appFlags: []Flag{StringFlag{Name: "requiredFlag", Required: true}, StringFlag{Name: "optional"}},
|
||||||
expectedAnError: true,
|
expectedAnError: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
testCase: "required_flag_input",
|
||||||
|
appRunInput: []string{"myCLI", "--requiredFlag", "cats"},
|
||||||
|
appFlags: []Flag{StringFlag{Name: "requiredFlag", Required: true}},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, test := range tdata {
|
for _, test := range tdata {
|
||||||
t.Run(test.testCase, func(t *testing.T) {
|
t.Run(test.testCase, func(t *testing.T) {
|
||||||
@ -925,7 +930,7 @@ func TestRequiredFlagAppRunBehavior(t *testing.T) {
|
|||||||
}
|
}
|
||||||
// setup - app
|
// setup - app
|
||||||
app := NewApp()
|
app := NewApp()
|
||||||
app.Flags = test.flags
|
app.Flags = test.appFlags
|
||||||
|
|
||||||
// logic under test
|
// logic under test
|
||||||
err := app.Run(test.appRunInput)
|
err := app.Run(test.appRunInput)
|
||||||
|
Loading…
Reference in New Issue
Block a user