Skip to content

Commit dedebb7

Browse files
committed
possible workaround for feature gate tests
1 parent 9b2906e commit dedebb7

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

api/v1beta1/azuremanagedcluster_webhook_test.go

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
. "github.com/onsi/gomega"
2323
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2424
utilfeature "k8s.io/component-base/featuregate/testing"
25+
"k8s.io/utils/ptr"
2526
"sigs.k8s.io/cluster-api-provider-azure/feature"
2627
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2728
capifeature "sigs.k8s.io/cluster-api/feature"
@@ -135,27 +136,29 @@ func TestAzureManagedCluster_ValidateCreate(t *testing.T) {
135136

136137
func TestAzureManagedCluster_ValidateCreateFailure(t *testing.T) {
137138
tests := []struct {
138-
name string
139-
amc *AzureManagedCluster
140-
deferFunc func()
141-
expectError bool
139+
name string
140+
amc *AzureManagedCluster
141+
featureGateEnabled *bool
142+
expectError bool
142143
}{
143144
{
144-
name: "feature gate explicitly disabled",
145-
amc: getKnownValidAzureManagedCluster(),
146-
deferFunc: utilfeature.SetFeatureGateDuringTest(t, feature.Gates, capifeature.MachinePool, false),
147-
expectError: true,
145+
name: "feature gate explicitly disabled",
146+
amc: getKnownValidAzureManagedCluster(),
147+
featureGateEnabled: ptr.To(false),
148+
expectError: true,
148149
},
149150
{
150-
name: "feature gate implicitly enabled",
151-
amc: getKnownValidAzureManagedCluster(),
152-
deferFunc: func() {},
153-
expectError: false,
151+
name: "feature gate implicitly enabled",
152+
amc: getKnownValidAzureManagedCluster(),
153+
featureGateEnabled: nil,
154+
expectError: false,
154155
},
155156
}
156157
for _, tc := range tests {
157158
t.Run(tc.name, func(t *testing.T) {
158-
defer tc.deferFunc()
159+
if tc.featureGateEnabled != nil {
160+
defer utilfeature.SetFeatureGateDuringTest(t, feature.Gates, capifeature.MachinePool, *tc.featureGateEnabled)()
161+
}
159162
g := NewWithT(t)
160163
_, err := tc.amc.ValidateCreate()
161164
if tc.expectError {

0 commit comments

Comments
 (0)