Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Larry Hitchon
committed
Mar 31, 2018
1 parent
bc91ddb
commit 4f7a0b0
Showing
5 changed files
with
82 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--- | ||
description: Test has-properties operator | ||
test_cases: | ||
|
||
- name: has-properties_OK | ||
rule: | ||
id: PROPERTIES_1 | ||
message: Missing properties | ||
severity: FAILURE | ||
resource: sample | ||
assertions: | ||
- key: example | ||
op: has-properties | ||
value: name,id | ||
resource: | ||
id: p1 | ||
type: sample | ||
properties: | ||
example: | ||
name: first | ||
id: 1 | ||
result: OK | ||
|
||
- name: has-properties_FAILURE | ||
rule: | ||
id: PROPERTIES_2 | ||
message: Missing properties | ||
severity: FAILURE | ||
resource: sample | ||
assertions: | ||
- key: example | ||
op: has-properties | ||
value: name,id,description | ||
resource: | ||
id: p1 | ||
type: sample | ||
properties: | ||
example: | ||
name: first | ||
id: 1 | ||
result: FAILURE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package assertion | ||
|
||
import ( | ||
"strings" | ||
) | ||
|
||
func has_properties(data interface{}, list string) (bool, error) { | ||
for _, key := range strings.Split(list, ",") { | ||
if m, ok := data.(map[string]interface{}); ok { | ||
if _, ok := m[key]; !ok { | ||
return false, nil | ||
} | ||
} | ||
} | ||
return true, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters