Skip to content

Commit 3043fbc

Browse files
Added feature gate to unit test
1 parent c0a1489 commit 3043fbc

File tree

1 file changed

+88
-2
lines changed

1 file changed

+88
-2
lines changed

pkg/api/pod/util_test.go

+88-2
Original file line numberDiff line numberDiff line change
@@ -4110,11 +4110,13 @@ func TestValidateAllowPodLifecycleSleepActionZeroValue(t *testing.T) {
41104110
testCases := []struct {
41114111
name string
41124112
podSpec *api.PodSpec
4113+
featureEnabled bool
41134114
expectAllowPodLifecycleSleepActionZeroValue bool
41144115
}{
41154116
{
4116-
name: "no lifecycle hooks",
4117-
podSpec: &api.PodSpec{},
4117+
name: "no lifecycle hooks",
4118+
podSpec: &api.PodSpec{},
4119+
featureEnabled: true,
41184120
expectAllowPodLifecycleSleepActionZeroValue: true,
41194121
},
41204122
{
@@ -4132,6 +4134,7 @@ func TestValidateAllowPodLifecycleSleepActionZeroValue(t *testing.T) {
41324134
},
41334135
},
41344136
},
4137+
featureEnabled: true,
41354138
expectAllowPodLifecycleSleepActionZeroValue: true,
41364139
},
41374140
{
@@ -4149,6 +4152,7 @@ func TestValidateAllowPodLifecycleSleepActionZeroValue(t *testing.T) {
41494152
},
41504153
},
41514154
},
4155+
featureEnabled: true,
41524156
expectAllowPodLifecycleSleepActionZeroValue: true,
41534157
},
41544158
{
@@ -4166,6 +4170,7 @@ func TestValidateAllowPodLifecycleSleepActionZeroValue(t *testing.T) {
41664170
},
41674171
},
41684172
},
4173+
featureEnabled: true,
41694174
expectAllowPodLifecycleSleepActionZeroValue: true,
41704175
},
41714176
{
@@ -4183,12 +4188,93 @@ func TestValidateAllowPodLifecycleSleepActionZeroValue(t *testing.T) {
41834188
},
41844189
},
41854190
},
4191+
featureEnabled: true,
4192+
expectAllowPodLifecycleSleepActionZeroValue: true,
4193+
},
4194+
{
4195+
name: "no lifecycle hooks with feature gate disabled",
4196+
podSpec: &api.PodSpec{},
4197+
featureEnabled: false,
4198+
expectAllowPodLifecycleSleepActionZeroValue: false,
4199+
},
4200+
{
4201+
name: "Prestop with non-zero second duration with feature gate disabled",
4202+
podSpec: &api.PodSpec{
4203+
Containers: []api.Container{
4204+
{
4205+
Lifecycle: &api.Lifecycle{
4206+
PreStop: &api.LifecycleHandler{
4207+
Sleep: &api.SleepAction{
4208+
Seconds: 1,
4209+
},
4210+
},
4211+
},
4212+
},
4213+
},
4214+
},
4215+
featureEnabled: false,
4216+
expectAllowPodLifecycleSleepActionZeroValue: false,
4217+
},
4218+
{
4219+
name: "PostStart with non-zero second duration with feature gate disabled",
4220+
podSpec: &api.PodSpec{
4221+
Containers: []api.Container{
4222+
{
4223+
Lifecycle: &api.Lifecycle{
4224+
PostStart: &api.LifecycleHandler{
4225+
Sleep: &api.SleepAction{
4226+
Seconds: 1,
4227+
},
4228+
},
4229+
},
4230+
},
4231+
},
4232+
},
4233+
featureEnabled: false,
4234+
expectAllowPodLifecycleSleepActionZeroValue: false,
4235+
},
4236+
{
4237+
name: "PreStop with zero seconds with feature gate disabled",
4238+
podSpec: &api.PodSpec{
4239+
Containers: []api.Container{
4240+
{
4241+
Lifecycle: &api.Lifecycle{
4242+
PreStop: &api.LifecycleHandler{
4243+
Sleep: &api.SleepAction{
4244+
Seconds: 0,
4245+
},
4246+
},
4247+
},
4248+
},
4249+
},
4250+
},
4251+
featureEnabled: false,
4252+
expectAllowPodLifecycleSleepActionZeroValue: true,
4253+
},
4254+
{
4255+
name: "PostStart with zero seconds with feature gate disabled",
4256+
podSpec: &api.PodSpec{
4257+
Containers: []api.Container{
4258+
{
4259+
Lifecycle: &api.Lifecycle{
4260+
PostStart: &api.LifecycleHandler{
4261+
Sleep: &api.SleepAction{
4262+
Seconds: 0,
4263+
},
4264+
},
4265+
},
4266+
},
4267+
},
4268+
},
4269+
featureEnabled: false,
41864270
expectAllowPodLifecycleSleepActionZeroValue: true,
41874271
},
41884272
}
41894273

41904274
for _, tc := range testCases {
41914275
t.Run(tc.name, func(t *testing.T) {
4276+
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodLifecycleSleepActionAllowZero, tc.featureEnabled)
4277+
41924278
gotOptions := GetValidationOptionsFromPodSpecAndMeta(&api.PodSpec{}, tc.podSpec, nil, nil)
41934279
assert.Equal(t, tc.expectAllowPodLifecycleSleepActionZeroValue, gotOptions.AllowPodLifecycleSleepActionZeroValue, "AllowPodLifecycleSleepActionZeroValue")
41944280
})

0 commit comments

Comments
 (0)