From 0b07f40c9b5518efd50d519d9cd439e92df1cf80 Mon Sep 17 00:00:00 2001 From: Huang Huang Date: Wed, 4 Mar 2020 00:54:38 +0800 Subject: [PATCH] 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 --- check/data | 20 ++++++++++++++++++++ check/test.go | 7 ++++++- check/test_test.go | 24 ++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/check/data b/check/data index 8711773..1930341 100644 --- a/check/data +++ b/check/data @@ -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: diff --git a/check/test.go b/check/test.go index be068b3..ece8ba9 100644 --- a/check/test.go +++ b/check/test.go @@ -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") diff --git a/check/test_test.go b/check/test_test.go index ff826e9..5323dc9 100644 --- a/check/test_test.go +++ b/check/test_test.go @@ -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 {