2021-09-26 18:30:53 -07:00
|
|
|
package response
|
|
|
|
|
|
|
|
import (
|
2021-10-29 11:24:26 +01:00
|
|
|
"testing"
|
|
|
|
|
2021-09-26 18:30:53 -07:00
|
|
|
"gopkg.in/yaml.v2"
|
|
|
|
"gotest.tools/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
var sourceYAML = `
|
|
|
|
policy:
|
|
|
|
name: disallow-bind-mounts
|
|
|
|
resource:
|
|
|
|
kind: Pod
|
|
|
|
apiVersion: v1
|
|
|
|
name: image-with-hostpath
|
|
|
|
rules:
|
|
|
|
- name: validate-hostPath
|
|
|
|
type: Validation
|
2021-09-30 00:04:13 -07:00
|
|
|
status: fail
|
2021-09-26 18:30:53 -07:00
|
|
|
`
|
|
|
|
|
|
|
|
func Test_parse_yaml(t *testing.T) {
|
|
|
|
var pr PolicyResponse
|
|
|
|
if err := yaml.Unmarshal([]byte(sourceYAML), &pr); err != nil {
|
|
|
|
t.Errorf("failed to parse YAML: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
assert.Equal(t, 1, len(pr.Rules))
|
|
|
|
assert.Equal(t, RuleStatusFail, pr.Rules[0].Status)
|
2021-09-27 23:40:05 -07:00
|
|
|
}
|