add test case for error inside variables.
This commit is contained in:
		| @@ -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) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Jiahui Feng
					Jiahui Feng