From 4b8a7ffbe1034c630c9fc194bf434f30f07b2b7e Mon Sep 17 00:00:00 2001
From: Abubakr-Sadik Nii Nai Davis <dwa2pac@gmail.com>
Date: Wed, 10 Apr 2019 22:47:26 +0000
Subject: [PATCH] Add ":" as a valid flag-value separator for tests

This is useful for checking values in YAML (possibly JSON) kubernetes config files.
---
 check/check.go     |  2 ++
 check/data         |  9 +++++++++
 check/test.go      |  2 +-
 check/test_test.go | 10 ++++++++++
 4 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/check/check.go b/check/check.go
index 0813858..4ace74b 100644
--- a/check/check.go
+++ b/check/check.go
@@ -166,6 +166,8 @@ func (c *Check) Run() {
 		i++
 	}
 
+	glog.V(3).Info(out.String())
+
 	finalOutput := c.Tests.execute(out.String())
 	if finalOutput != nil {
 		c.ActualValue = finalOutput.actualResult
diff --git a/check/data b/check/data
index 88bdc85..cfc65ca 100644
--- a/check/data
+++ b/check/data
@@ -158,3 +158,12 @@ groups:
             set: true
 
 
+    - id: 14
+      text: "check that flag some-arg is set to some-val with ':' separator"
+      tests:
+        test_items:
+          - flag: "some-arg"
+            compare:
+              op: eq
+              value: some-val
+            set: true
diff --git a/check/test.go b/check/test.go
index 7a74634..9289b0a 100644
--- a/check/test.go
+++ b/check/test.go
@@ -68,7 +68,7 @@ func (t *testItem) execute(s string) *testOutput {
 			// --flag
 			// somevalue
 			//pttn := `(` + t.Flag + `)(=)*([^\s,]*) *`
-			pttn := `(` + t.Flag + `)(=)*([^\s]*) *`
+			pttn := `(` + t.Flag + `)(=|: *)*([^\s]*) *`
 			flagRe := regexp.MustCompile(pttn)
 			vals := flagRe.FindStringSubmatch(s)
 
diff --git a/check/test_test.go b/check/test_test.go
index 4b96e07..72e4f46 100644
--- a/check/test_test.go
+++ b/check/test_test.go
@@ -110,6 +110,16 @@ func TestTestExecute(t *testing.T) {
 			controls.Groups[0].Checks[13],
 			"2:45 ../kubernetes/kube-apiserver --option --admission-control=Something ---audit-log-maxage=40",
 		},
+		{
+			// check for ':' as argument-value separator, with space between arg and val
+			controls.Groups[0].Checks[14],
+			"2:45 kube-apiserver some-arg: some-val --admission-control=Something ---audit-log-maxage=40",
+		},
+		{
+			// check for ':' as argument-value separator, with no space between arg and val
+			controls.Groups[0].Checks[14],
+			"2:45 kube-apiserver some-arg:some-val --admission-control=Something ---audit-log-maxage=40",
+		},
 	}
 
 	for _, c := range cases {
-- 
GitLab