@@ -5161,3 +5161,64 @@ func TestTransformDRADriverController(t *testing.T) {
51615161 })
51625162 }
51635163}
5164+
5165+ func TestApplyDRAFeatureGates (t * testing.T ) {
5166+ testCases := []struct {
5167+ description string
5168+ gates map [string ]bool
5169+ initialEnv []corev1.EnvVar
5170+ expectedEnv []corev1.EnvVar
5171+ }{
5172+ {
5173+ description : "empty map is a no-op" ,
5174+ gates : map [string ]bool {},
5175+ initialEnv : []corev1.EnvVar {{Name : "KEEP_ME" , Value : "yes" }},
5176+ expectedEnv : []corev1.EnvVar {{Name : "KEEP_ME" , Value : "yes" }},
5177+ },
5178+ {
5179+ description : "nil map is a no-op" ,
5180+ gates : nil ,
5181+ initialEnv : []corev1.EnvVar {{Name : "KEEP_ME" , Value : "yes" }},
5182+ expectedEnv : []corev1.EnvVar {{Name : "KEEP_ME" , Value : "yes" }},
5183+ },
5184+ {
5185+ description : "single gate renders Key=true with trailing comma" ,
5186+ gates : map [string ]bool {"NVMLDeviceHealthCheck" : true },
5187+ expectedEnv : []corev1.EnvVar {{Name : "FEATURE_GATES" , Value : "NVMLDeviceHealthCheck=true," }},
5188+ },
5189+ {
5190+ description : "multiple gates render in alphabetical order" ,
5191+ gates : map [string ]bool {"DynamicMIG" : false , "NVMLDeviceHealthCheck" : true , "MPSSupport" : true },
5192+ expectedEnv : []corev1.EnvVar {{Name : "FEATURE_GATES" , Value : "DynamicMIG=false,MPSSupport=true,NVMLDeviceHealthCheck=true," }},
5193+ },
5194+ {
5195+ description : "overwrites existing FEATURE_GATES entry without duplicating" ,
5196+ gates : map [string ]bool {"DynamicMIG" : true },
5197+ initialEnv : []corev1.EnvVar {
5198+ {Name : "FEATURE_GATES" , Value : "stale=true," },
5199+ {Name : "OTHER" , Value : "preserved" },
5200+ },
5201+ expectedEnv : []corev1.EnvVar {
5202+ {Name : "FEATURE_GATES" , Value : "DynamicMIG=true," },
5203+ {Name : "OTHER" , Value : "preserved" },
5204+ },
5205+ },
5206+ {
5207+ description : "appends FEATURE_GATES when not present, preserves siblings" ,
5208+ gates : map [string ]bool {"DynamicMIG" : true },
5209+ initialEnv : []corev1.EnvVar {{Name : "OTHER" , Value : "preserved" }},
5210+ expectedEnv : []corev1.EnvVar {
5211+ {Name : "OTHER" , Value : "preserved" },
5212+ {Name : "FEATURE_GATES" , Value : "DynamicMIG=true," },
5213+ },
5214+ },
5215+ }
5216+
5217+ for _ , tc := range testCases {
5218+ t .Run (tc .description , func (t * testing.T ) {
5219+ c := & corev1.Container {Env : tc .initialEnv }
5220+ applyDRAFeatureGates (c , tc .gates )
5221+ assert .Equal (t , tc .expectedEnv , c .Env )
5222+ })
5223+ }
5224+ }
0 commit comments