@@ -3,6 +3,7 @@ package validator
33import (
44 "fmt"
55 "io/ioutil"
6+ "reflect"
67 "testing"
78)
89
@@ -13,15 +14,15 @@ func Test_PolicyEval(t *testing.T) {
1314 policy string
1415 pkgName string
1516 policyRule []string
16- want bool
17+ want interface {}
1718 wantError error
1819 }{
1920 {name : "test validate policy deny pod name json format" , data : "./fixture/pod.json" , policyRule : []string {"example.deny" }, policy : "./fixture/pod_policy_deny" , want : true , wantError : nil },
2021 {name : "test validate policy deny pod name yaml format" , data : "./fixture/pod.yaml" , policyRule : []string {"example.deny" }, policy : "./fixture/pod_policy_deny" , want : true , wantError : nil },
2122 {name : "test validate policy allow pod name" , data : "./fixture/allow_pod.json" , policyRule : []string {"example.deny" }, policy : "./fixture/pod_policy_deny" , want : false , wantError : nil },
2223 {name : "test validate policy bad data" , data : "./fixture/badJson.json" , policyRule : []string {"example.deny" }, policy : "./fixture/pod_policy_deny" , want : false , wantError : nil },
2324 {name : "test validate policy bad policy" , data : "./fixture/badJson.json" , policyRule : []string {"example.deny" }, policy : "./fixture/pod_policy_deny_bad" , want : false , wantError : fmt .Errorf ("1 error occurred: eval.rego:5: rego_parse_error: unexpected } token\n \t }\n \t ^" )},
24- {name : "test validate policy bad policy" , data : "./fixture/strict_policy.json" , policyRule : []string {"itsio.allow" }, policy : "./fixture/deny_strict.policy" , want : true , wantError : nil },
25+ {name : "test validate policy bad policy" , data : "./fixture/strict_policy.json" , policyRule : []string {"itsio.allow" }, policy : "./fixture/deny_strict.policy" , want : map [ string ] interface {}{ "allow_policy" : true , "name" : "foo" } , wantError : nil },
2526 }
2627 for _ , tt := range tests {
2728 t .Run (tt .name , func (t * testing.T ) {
@@ -41,7 +42,7 @@ func Test_PolicyEval(t *testing.T) {
4142 }
4243 }
4344 if err == nil {
44- if got [0 ].Value != tt .want {
45+ if eq := reflect . DeepEqual ( got [0 ].ExpressionValue [ 0 ]. Value , tt .want ); ! eq {
4546 t .Errorf ("Test_PolicyEval() = %v, want %v" , got [0 ], tt .want )
4647 }
4748 }
0 commit comments