@@ -118,7 +118,7 @@ func TestDropAlphaPVCVolumeMode(t *testing.T) {
118
118
}
119
119
}
120
120
121
- func TestDropDisabledDataSource (t * testing.T ) {
121
+ func TestDropDisabledSnapshotDataSource (t * testing.T ) {
122
122
pvcWithoutDataSource := func () * core.PersistentVolumeClaim {
123
123
return & core.PersistentVolumeClaim {
124
124
Spec : core.PersistentVolumeClaimSpec {
@@ -210,3 +210,74 @@ func TestDropDisabledDataSource(t *testing.T) {
210
210
}
211
211
}
212
212
}
213
+
214
+ // TestPVCDataSourceSpecFilter checks to ensure the DropDisabledFields function behaves correctly for PVCDataSource featuregate
215
+ func TestPVCDataSourceSpecFilter (t * testing.T ) {
216
+ apiGroup := ""
217
+ validSpec := core.PersistentVolumeClaimSpec {
218
+ DataSource : & core.TypedLocalObjectReference {
219
+ APIGroup : & apiGroup ,
220
+ Kind : "PersistentVolumeClaim" ,
221
+ Name : "test_clone" ,
222
+ },
223
+ }
224
+
225
+ invalidAPIGroup := "invalid.pvc.api.group"
226
+ invalidSpec := core.PersistentVolumeClaimSpec {
227
+ DataSource : & core.TypedLocalObjectReference {
228
+ APIGroup : & invalidAPIGroup ,
229
+ Kind : "PersistentVolumeClaim" ,
230
+ Name : "test_clone_invalid" ,
231
+ },
232
+ }
233
+
234
+ var tests = map [string ]struct {
235
+ spec core.PersistentVolumeClaimSpec
236
+ gateEnabled bool
237
+ want * core.TypedLocalObjectReference
238
+ }{
239
+ "enabled with empty ds" : {
240
+ spec : core.PersistentVolumeClaimSpec {},
241
+ gateEnabled : true ,
242
+ want : nil ,
243
+ },
244
+ "enabled with invalid spec" : {
245
+ spec : invalidSpec ,
246
+ gateEnabled : true ,
247
+ want : nil ,
248
+ },
249
+ "enabled with valid spec" : {
250
+ spec : validSpec ,
251
+ gateEnabled : true ,
252
+ want : validSpec .DataSource ,
253
+ },
254
+ "disabled with invalid spec" : {
255
+ spec : invalidSpec ,
256
+ gateEnabled : false ,
257
+ want : nil ,
258
+ },
259
+ "disabled with valid spec" : {
260
+ spec : validSpec ,
261
+ gateEnabled : false ,
262
+ want : nil ,
263
+ },
264
+ "diabled with empty ds" : {
265
+ spec : core.PersistentVolumeClaimSpec {},
266
+ gateEnabled : false ,
267
+ want : nil ,
268
+ },
269
+ }
270
+
271
+ for testName , test := range tests {
272
+ t .Run (testName , func (t * testing.T ) {
273
+ defer featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .VolumePVCDataSource , test .gateEnabled )()
274
+ DropDisabledFields (& test .spec , nil )
275
+ if test .spec .DataSource != test .want {
276
+ t .Errorf ("expected drop datasource condition was not met, test: %s, gateEnabled: %v, spec: %v, expected: %v" , testName , test .gateEnabled , test .spec , test .want )
277
+ }
278
+
279
+ })
280
+
281
+ }
282
+
283
+ }
0 commit comments