flowcontrol: cover Required rule for spec.type and limitResponse.type

Add declarative-validation test cases for empty Spec.Type and empty
LimitResponse.Type, closing the FieldValueRequired coverage gap reported
for PriorityLevelConfiguration across v1, v1beta1, v1beta2, v1beta3.
This commit is contained in:
Yongrui Lin 2026-05-01 23:29:40 +00:00
parent 177d2ae7a1
commit 55baca8a46

View file

@ -103,6 +103,18 @@ func testDeclarativeValidate(t *testing.T, apiVersion string) {
field.Forbidden(specPath.Child("limited", "limitResponse", "queuing"), "").MarkCoveredByDeclarative().MarkAlpha(),
},
},
"spec.type: empty": {
input: mkPLC(tweakSpecType(""), tweakLimited(nil)),
expectedErrs: field.ErrorList{
field.Required(specPath.Child("type"), "").MarkCoveredByDeclarative().MarkAlpha(),
},
},
"limitResponse.type: empty": {
input: mkPLC(tweakLimitResponseType("")),
expectedErrs: field.ErrorList{
field.Required(specPath.Child("limited", "limitResponse", "type"), "").MarkCoveredByDeclarative().MarkAlpha(),
},
},
}
for name, tc := range testCases {
@ -226,6 +238,13 @@ func tweakLimited(limited *flowcontrol.LimitedPriorityLevelConfiguration) func(*
}
}
// tweakSpecType sets the Spec.Type field directly.
func tweakSpecType(t flowcontrol.PriorityLevelEnablement) func(*flowcontrol.PriorityLevelConfiguration) {
return func(obj *flowcontrol.PriorityLevelConfiguration) {
obj.Spec.Type = t
}
}
// tweakExemptConfig sets the Exempt configuration field.
func tweakExemptConfig(exempt *flowcontrol.ExemptPriorityLevelConfiguration) func(*flowcontrol.PriorityLevelConfiguration) {
return func(obj *flowcontrol.PriorityLevelConfiguration) {