Make matchConditionsFeatureGateInitiallyEnabled a boolean instead

This commit is contained in:
Amine 2023-07-17 18:34:42 +01:00
parent 6b3ce3004d
commit 00de051729

View File

@ -730,20 +730,20 @@ func TestMatchConditions_validation(t *testing.T) {
func TestFeatureGateEnablement(t *testing.T) { func TestFeatureGateEnablement(t *testing.T) {
testcases := []struct { testcases := []struct {
name string name string
matchConditionsFeatureGateInitiaState string matchConditionsFeatureGateInitiallyEnabled bool
matchConditions []admissionregistrationv1.MatchCondition matchConditions []admissionregistrationv1.MatchCondition
expectMatchConditionsPreSwitch bool expectMatchConditionsPreSwitch bool
expectMatchConditionsPostSwitch bool expectMatchConditionsPostSwitch bool
}{ }{
{ {
name: "start with match conditions enabled - no match conditions", name: "start with match conditions enabled - no match conditions",
matchConditionsFeatureGateInitiaState: "enabled", matchConditionsFeatureGateInitiallyEnabled: true,
expectMatchConditionsPreSwitch: false, expectMatchConditionsPreSwitch: false,
expectMatchConditionsPostSwitch: false, expectMatchConditionsPostSwitch: false,
}, },
{ {
name: "start with match conditions enabled - with match conditions", name: "start with match conditions enabled - with match conditions",
matchConditionsFeatureGateInitiaState: "enabled", matchConditionsFeatureGateInitiallyEnabled: true,
matchConditions: []admissionregistrationv1.MatchCondition{{ matchConditions: []admissionregistrationv1.MatchCondition{{
Name: "test-expression", Name: "test-expression",
Expression: "true", Expression: "true",
@ -753,13 +753,13 @@ func TestFeatureGateEnablement(t *testing.T) {
}, },
{ {
name: "start with match conditions disabled - no match conditions", name: "start with match conditions disabled - no match conditions",
matchConditionsFeatureGateInitiaState: "disabled", matchConditionsFeatureGateInitiallyEnabled: false,
expectMatchConditionsPreSwitch: false, expectMatchConditionsPreSwitch: false,
expectMatchConditionsPostSwitch: false, expectMatchConditionsPostSwitch: false,
}, },
{ {
name: "start with match conditions disabled - with match conditions", name: "start with match conditions disabled - with match conditions",
matchConditionsFeatureGateInitiaState: "disabled", matchConditionsFeatureGateInitiallyEnabled: false,
matchConditions: []admissionregistrationv1.MatchCondition{{ matchConditions: []admissionregistrationv1.MatchCondition{{
Name: "test-expression", Name: "test-expression",
Expression: "true", Expression: "true",
@ -794,7 +794,7 @@ func TestFeatureGateEnablement(t *testing.T) {
for _, testcase := range testcases { for _, testcase := range testcases {
t.Run(testcase.name, func(t *testing.T) { t.Run(testcase.name, func(t *testing.T) {
if testcase.matchConditionsFeatureGateInitiaState == "enabled" { if testcase.matchConditionsFeatureGateInitiallyEnabled {
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.AdmissionWebhookMatchConditions, true)() defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.AdmissionWebhookMatchConditions, true)()
} }
@ -887,7 +887,7 @@ func TestFeatureGateEnablement(t *testing.T) {
} }
// Switch the featureGate state // Switch the featureGate state
if testcase.matchConditionsFeatureGateInitiaState == "enabled" { if testcase.matchConditionsFeatureGateInitiallyEnabled {
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.AdmissionWebhookMatchConditions, false)() defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.AdmissionWebhookMatchConditions, false)()
} else { } else {
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.AdmissionWebhookMatchConditions, true)() defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.AdmissionWebhookMatchConditions, true)()