Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 45 additions & 5 deletions api/policies.kyverno.io/v1beta1/policy_exception_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestCELPolicyException_GetKind(t *testing.T) {
policy: &PolicyException{},
want: "PolicyException",
}, {
name: "not set",
name: "kind overridden",
policy: &PolicyException{
TypeMeta: v1.TypeMeta{
Kind: "Foo",
Expand Down Expand Up @@ -90,17 +90,57 @@ func TestCELPolicyExceptionSpec_Validate(t *testing.T) {
BadValue: "",
Detail: "must specify policy name",
}},
},
// TODO: Add test cases.
}
}, {
name: "ref no kind and name",
policy: &PolicyException{
Spec: PolicyExceptionSpec{
PolicyRefs: []PolicyRef{{}},
},
},
wantErrs: field.ErrorList{{
Type: field.ErrorTypeInvalid,
Field: "spec.policyRefs[0].name",
BadValue: "",
Detail: "must specify policy name",
}, {
Type: field.ErrorTypeInvalid,
Field: "spec.policyRefs[0].kind",
BadValue: "",
Detail: "must specify policy kind",
}},
}, {
name: "multiple refs with indexed errors",
policy: &PolicyException{
Spec: PolicyExceptionSpec{
PolicyRefs: []PolicyRef{{
Name: "foo",
Kind: "Foo",
}, {
Name: "bar",
}, {
Kind: "Baz",
}},
},
},
wantErrs: field.ErrorList{{
Type: field.ErrorTypeInvalid,
Field: "spec.policyRefs[1].kind",
BadValue: "",
Detail: "must specify policy kind",
}, {
Type: field.ErrorTypeInvalid,
Field: "spec.policyRefs[2].name",
BadValue: "",
Detail: "must specify policy name",
}},
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotErrs := tt.policy.Validate()
assert.Equal(t, tt.wantErrs, gotErrs)
})
}
}

func TestCELPolicyException_IsExpired(t *testing.T) {
tests := []struct {
name string
Expand Down