@@ -17,7 +17,6 @@ limitations under the License.
17
17
package persistentvolume
18
18
19
19
import (
20
- "fmt"
21
20
"reflect"
22
21
"testing"
23
22
@@ -153,99 +152,3 @@ func TestDropDisabledFields(t *testing.T) {
153
152
})
154
153
}
155
154
}
156
-
157
- func TestDropDisabledFieldsPersistentLocalVolume (t * testing.T ) {
158
- pvWithoutLocalVolume := func () * api.PersistentVolume {
159
- return & api.PersistentVolume {
160
- Spec : api.PersistentVolumeSpec {
161
- PersistentVolumeSource : api.PersistentVolumeSource {
162
- Local : nil ,
163
- },
164
- },
165
- }
166
- }
167
- pvWithLocalVolume := func () * api.PersistentVolume {
168
- fsType := "ext4"
169
- return & api.PersistentVolume {
170
- Spec : api.PersistentVolumeSpec {
171
- PersistentVolumeSource : api.PersistentVolumeSource {
172
- Local : & api.LocalVolumeSource {
173
- Path : "/a/b/c" ,
174
- FSType : & fsType ,
175
- },
176
- },
177
- },
178
- }
179
- }
180
-
181
- pvInfo := []struct {
182
- description string
183
- hasLocalVolume bool
184
- pv func () * api.PersistentVolume
185
- }{
186
- {
187
- description : "pv without LocalVolume" ,
188
- hasLocalVolume : false ,
189
- pv : pvWithoutLocalVolume ,
190
- },
191
- {
192
- description : "pv with LocalVolume" ,
193
- hasLocalVolume : true ,
194
- pv : pvWithLocalVolume ,
195
- },
196
- {
197
- description : "is nil" ,
198
- hasLocalVolume : false ,
199
- pv : func () * api.PersistentVolume { return nil },
200
- },
201
- }
202
-
203
- for _ , enabled := range []bool {true , false } {
204
- for _ , oldpvInfo := range pvInfo {
205
- for _ , newpvInfo := range pvInfo {
206
- oldpvHasLocalVolume , oldpv := oldpvInfo .hasLocalVolume , oldpvInfo .pv ()
207
- newpvHasLocalVolume , newpv := newpvInfo .hasLocalVolume , newpvInfo .pv ()
208
- if newpv == nil {
209
- continue
210
- }
211
-
212
- t .Run (fmt .Sprintf ("feature enabled=%v, old pvc %v, new pvc %v" , enabled , oldpvInfo .description , newpvInfo .description ), func (t * testing.T ) {
213
- defer utilfeaturetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .PersistentLocalVolumes , enabled )()
214
-
215
- var oldpvSpec * api.PersistentVolumeSpec
216
- if oldpv != nil {
217
- oldpvSpec = & oldpv .Spec
218
- }
219
- DropDisabledFields (& newpv .Spec , oldpvSpec )
220
-
221
- // old pv should never be changed
222
- if ! reflect .DeepEqual (oldpv , oldpvInfo .pv ()) {
223
- t .Errorf ("old pv changed: %v" , diff .ObjectReflectDiff (oldpv , oldpvInfo .pv ()))
224
- }
225
-
226
- switch {
227
- case enabled || oldpvHasLocalVolume :
228
- // new pv should not be changed if the feature is enabled, or if the old pv had LocalVolume source
229
- if ! reflect .DeepEqual (newpv , newpvInfo .pv ()) {
230
- t .Errorf ("new pv changed: %v" , diff .ObjectReflectDiff (newpv , newpvInfo .pv ()))
231
- }
232
- case newpvHasLocalVolume :
233
- // new pv should be changed
234
- if reflect .DeepEqual (newpv , newpvInfo .pv ()) {
235
- t .Errorf ("new pv was not changed" )
236
- }
237
- // new pv should not have LocalVolume
238
- if ! reflect .DeepEqual (newpv , pvWithoutLocalVolume ()) {
239
- t .Errorf ("new pv had LocalVolume source: %v" , diff .ObjectReflectDiff (newpv , pvWithoutLocalVolume ()))
240
- }
241
- default :
242
- // new pv should not need to be changed
243
- if ! reflect .DeepEqual (newpv , newpvInfo .pv ()) {
244
- t .Errorf ("new pv changed: %v" , diff .ObjectReflectDiff (newpv , newpvInfo .pv ()))
245
- }
246
- }
247
- })
248
- }
249
- }
250
- }
251
- }
0 commit comments