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

Function TestCheckRequiredFlags

command_test.go:4586–4748  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

4584}
4585
4586func TestCheckRequiredFlags(t *testing.T) {
4587 tdata := []struct {
4588 testCase string
4589 parseInput []string
4590 envVarInput [2]string
4591 flags []Flag
4592 expectedAnError bool
4593 expectedErrorContents []string
4594 }{
4595 {
4596 testCase: "empty",
4597 },
4598 {
4599 testCase: "optional",
4600 flags: []Flag{
4601 &StringFlag{Name: "optionalFlag"},
4602 },
4603 },
4604 {
4605 testCase: "required",
4606 flags: []Flag{
4607 &StringFlag{Name: "requiredFlag", Required: true},
4608 },
4609 expectedAnError: true,
4610 expectedErrorContents: []string{"requiredFlag"},
4611 },
4612 {
4613 testCase: "required_and_present",
4614 flags: []Flag{
4615 &StringFlag{Name: "requiredFlag", Required: true},
4616 },
4617 parseInput: []string{"--requiredFlag", "myinput"},
4618 },
4619 {
4620 testCase: "required_and_present_via_env_var",
4621 flags: []Flag{
4622 &StringFlag{Name: "requiredFlag", Required: true, Sources: EnvVars("REQUIRED_FLAG")},
4623 },
4624 envVarInput: [2]string{"REQUIRED_FLAG", "true"},
4625 },
4626 {
4627 testCase: "required_and_optional",
4628 flags: []Flag{
4629 &StringFlag{Name: "requiredFlag", Required: true},
4630 &StringFlag{Name: "optionalFlag"},
4631 },
4632 expectedAnError: true,
4633 },
4634 {
4635 testCase: "required_and_optional_and_optional_present",
4636 flags: []Flag{
4637 &StringFlag{Name: "requiredFlag", Required: true},
4638 &StringFlag{Name: "optionalFlag"},
4639 },
4640 parseInput: []string{"--optionalFlag", "myinput"},
4641 expectedAnError: true,
4642 },
4643 {

Callers

nothing calls this directly

Calls 3

RunMethod · 0.95
checkAllRequiredFlagsMethod · 0.95
EnvVarsFunction · 0.85

Tested by

no test coverage detected