Support parse boolean flag with no value (#579)

* Support parse boolean flag with no value

* Add test for parse boolean flag with false value

Co-authored-by: Roberto Rojas <robertojrojas@gmail.com>
pull/586/head^2
Huang Huang 4 years ago committed by GitHub
parent d988b81540
commit 0b07f40c9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -308,6 +308,26 @@ groups:
value: '^1\.12.*$'
set: true
- id: 27
text: "check boolean flag with no value"
tests:
test_items:
- flag: "--peer-client-cert-auth"
compare:
op: eq
value: true
set: true
- id: 28
text: "check boolean flag with false value"
tests:
test_items:
- flag: "--peer-client-cert-auth"
compare:
op: eq
value: false
set: true
- id: 2.1
text: "audit and audit_config commands"
checks:

@ -115,7 +115,12 @@ func (t *testItem) execute(s string) *testOutput {
if vals[3] != "" {
flagVal = vals[3]
} else {
flagVal = vals[1]
// --bool-flag
if strings.HasPrefix(t.Flag, "--") {
flagVal = "true"
} else {
flagVal = vals[1]
}
}
} else {
fmt.Fprintf(os.Stderr, "invalid flag in testitem definition")

@ -156,6 +156,30 @@ func TestTestExecute(t *testing.T) {
controls.Groups[0].Checks[26],
"currentMasterVersion: 1.12.7",
},
{
controls.Groups[0].Checks[27],
"--peer-client-cert-auth",
},
{
controls.Groups[0].Checks[27],
"--abc=true --peer-client-cert-auth --efg=false",
},
{
controls.Groups[0].Checks[27],
"--abc --peer-client-cert-auth --efg",
},
{
controls.Groups[0].Checks[27],
"--peer-client-cert-auth=true",
},
{
controls.Groups[0].Checks[27],
"--abc --peer-client-cert-auth=true --efg",
},
{
controls.Groups[0].Checks[28],
"--abc --peer-client-cert-auth=false --efg",
},
}
for _, c := range cases {

Loading…
Cancel
Save