1
0
mirror of https://github.com/aquasecurity/kube-bench.git synced 2024-12-19 13:18:07 +00:00

Generate expected result by strings join

This commit is contained in:
Yoav Hizkiahou 2019-05-21 14:10:11 +03:00
parent d1c3e3163b
commit ddb677bc69

View File

@ -219,8 +219,11 @@ func (ts *tests) execute(s string) *testOutput {
return finalOutput return finalOutput
} }
expectedResultArr := make([]string, len(res))
for i, t := range ts.TestItems { for i, t := range ts.TestItems {
res[i] = *(t.execute(s)) res[i] = *(t.execute(s))
expectedResultArr[i] = res[i].ExpectedResult
} }
var result bool var result bool
@ -232,19 +235,18 @@ func (ts *tests) execute(s string) *testOutput {
case and, "": case and, "":
result = true result = true
for i := range res { for i := range res {
finalOutput.ExpectedResult += fmt.Sprintf("%s AND ", res[i].ExpectedResult)
result = result && res[i].testResult result = result && res[i].testResult
} }
// Delete last iteration ' AND ' // Generate an AND expected result
finalOutput.ExpectedResult = finalOutput.ExpectedResult[:len(finalOutput.ExpectedResult)-5] finalOutput.ExpectedResult = strings.Join(expectedResultArr, " AND ")
case or: case or:
result = false result = false
for i := range res { for i := range res {
finalOutput.ExpectedResult += fmt.Sprintf("%s OR ", res[i].ExpectedResult)
result = result || res[i].testResult result = result || res[i].testResult
} }
// Delete last iteration ' OR ' // Generate an OR expected result
finalOutput.ExpectedResult = finalOutput.ExpectedResult[:len(finalOutput.ExpectedResult)-4] finalOutput.ExpectedResult = strings.Join(expectedResultArr, " OR ")
} }
finalOutput.testResult = result finalOutput.testResult = result