add test case for error inside variables.

Kubernetes-commit: 3e777540fda8dda01bb72702b1e39675f21d2955
This commit is contained in:
Jiahui Feng 2024-02-08 13:39:25 -08:00 committed by Kubernetes Publisher
parent ab64beb117
commit 6f620d4d18
1 changed files with 29 additions and 0 deletions

View File

@ -502,6 +502,35 @@ func TestTypeCheck(t *testing.T) {
toContain("found no matching overload for '_==_' applied to '(string, int)"),
},
},
{
name: "error in variables, not reported during type checking.",
policy: &v1beta1.ValidatingAdmissionPolicy{Spec: v1beta1.ValidatingAdmissionPolicySpec{
Variables: []v1beta1.Variable{
{
Name: "name",
Expression: "object.foo == 'str'",
},
},
Validations: []v1beta1.Validation{
{
Expression: "variables.name == object.foo", // foo is int64
},
},
MatchConstraints: deploymentPolicy.Spec.MatchConstraints,
},
},
schemaToReturn: &spec.Schema{
SchemaProps: spec.SchemaProps{
Type: []string{"object"},
Properties: map[string]spec.Schema{
"foo": *spec.Int64Property(),
},
},
},
assertions: []assertionFunc{
toHaveLengthOf(0),
},
},
} {
t.Run(tc.name, func(t *testing.T) {
typeChecker := buildTypeChecker(tc.schemaToReturn)