Added feature gate to unit test

This commit is contained in:
Sreeram 2025-03-19 23:09:41 +05:30
parent c0a1489bc8
commit 3043fbc3da

View File

@ -4110,11 +4110,13 @@ func TestValidateAllowPodLifecycleSleepActionZeroValue(t *testing.T) {
testCases := []struct {
name string
podSpec *api.PodSpec
featureEnabled bool
expectAllowPodLifecycleSleepActionZeroValue bool
}{
{
name: "no lifecycle hooks",
podSpec: &api.PodSpec{},
name: "no lifecycle hooks",
podSpec: &api.PodSpec{},
featureEnabled: true,
expectAllowPodLifecycleSleepActionZeroValue: true,
},
{
@ -4132,6 +4134,7 @@ func TestValidateAllowPodLifecycleSleepActionZeroValue(t *testing.T) {
},
},
},
featureEnabled: true,
expectAllowPodLifecycleSleepActionZeroValue: true,
},
{
@ -4149,6 +4152,7 @@ func TestValidateAllowPodLifecycleSleepActionZeroValue(t *testing.T) {
},
},
},
featureEnabled: true,
expectAllowPodLifecycleSleepActionZeroValue: true,
},
{
@ -4166,6 +4170,7 @@ func TestValidateAllowPodLifecycleSleepActionZeroValue(t *testing.T) {
},
},
},
featureEnabled: true,
expectAllowPodLifecycleSleepActionZeroValue: true,
},
{
@ -4183,12 +4188,93 @@ func TestValidateAllowPodLifecycleSleepActionZeroValue(t *testing.T) {
},
},
},
featureEnabled: true,
expectAllowPodLifecycleSleepActionZeroValue: true,
},
{
name: "no lifecycle hooks with feature gate disabled",
podSpec: &api.PodSpec{},
featureEnabled: false,
expectAllowPodLifecycleSleepActionZeroValue: false,
},
{
name: "Prestop with non-zero second duration with feature gate disabled",
podSpec: &api.PodSpec{
Containers: []api.Container{
{
Lifecycle: &api.Lifecycle{
PreStop: &api.LifecycleHandler{
Sleep: &api.SleepAction{
Seconds: 1,
},
},
},
},
},
},
featureEnabled: false,
expectAllowPodLifecycleSleepActionZeroValue: false,
},
{
name: "PostStart with non-zero second duration with feature gate disabled",
podSpec: &api.PodSpec{
Containers: []api.Container{
{
Lifecycle: &api.Lifecycle{
PostStart: &api.LifecycleHandler{
Sleep: &api.SleepAction{
Seconds: 1,
},
},
},
},
},
},
featureEnabled: false,
expectAllowPodLifecycleSleepActionZeroValue: false,
},
{
name: "PreStop with zero seconds with feature gate disabled",
podSpec: &api.PodSpec{
Containers: []api.Container{
{
Lifecycle: &api.Lifecycle{
PreStop: &api.LifecycleHandler{
Sleep: &api.SleepAction{
Seconds: 0,
},
},
},
},
},
},
featureEnabled: false,
expectAllowPodLifecycleSleepActionZeroValue: true,
},
{
name: "PostStart with zero seconds with feature gate disabled",
podSpec: &api.PodSpec{
Containers: []api.Container{
{
Lifecycle: &api.Lifecycle{
PostStart: &api.LifecycleHandler{
Sleep: &api.SleepAction{
Seconds: 0,
},
},
},
},
},
},
featureEnabled: false,
expectAllowPodLifecycleSleepActionZeroValue: true,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodLifecycleSleepActionAllowZero, tc.featureEnabled)
gotOptions := GetValidationOptionsFromPodSpecAndMeta(&api.PodSpec{}, tc.podSpec, nil, nil)
assert.Equal(t, tc.expectAllowPodLifecycleSleepActionZeroValue, gotOptions.AllowPodLifecycleSleepActionZeroValue, "AllowPodLifecycleSleepActionZeroValue")
})