@@ -28,14 +28,15 @@ import (
28
28
29
29
func TestGetChangedBlockMetadata (t * testing.T ) {
30
30
testCases := []struct {
31
- name string
32
- sourceFileBlocks int
33
- targetFileBlocks int
34
- changedBlocks []int
35
- startingOffset int64
36
- maxResult int32
37
- expectedResponse []* csi.BlockMetadata
38
- expectErr bool
31
+ name string
32
+ sourceFileBlocks int
33
+ targetFileBlocks int
34
+ changedBlocks []int
35
+ blockMetadataType csi.BlockMetadataType
36
+ startingOffset int64
37
+ maxResult int32
38
+ expectedResponse []* csi.BlockMetadata
39
+ expectErr bool
39
40
}{
40
41
{
41
42
name : "success case" ,
@@ -211,6 +212,57 @@ func TestGetChangedBlockMetadata(t *testing.T) {
211
212
},
212
213
expectErr : false ,
213
214
},
215
+ {
216
+ name : "success case with variable block sizes" ,
217
+ sourceFileBlocks : 100 ,
218
+ targetFileBlocks : 100 ,
219
+ changedBlocks : []int {3 , 4 , 5 , 6 , 7 , 47 , 48 , 49 , 51 },
220
+ blockMetadataType : csi .BlockMetadataType_VARIABLE_LENGTH ,
221
+ maxResult : 100 ,
222
+ expectedResponse : []* csi.BlockMetadata {
223
+ {
224
+ ByteOffset : 3 * state .BlockSizeBytes ,
225
+ SizeBytes : state .BlockSizeBytes * 5 ,
226
+ },
227
+ {
228
+ ByteOffset : 47 * state .BlockSizeBytes ,
229
+ SizeBytes : state .BlockSizeBytes * 3 ,
230
+ },
231
+ {
232
+ ByteOffset : 51 * state .BlockSizeBytes ,
233
+ SizeBytes : state .BlockSizeBytes ,
234
+ },
235
+ },
236
+ expectErr : false ,
237
+ },
238
+ {
239
+ name : "success case with starting offset and variable length" ,
240
+ sourceFileBlocks : 100 ,
241
+ targetFileBlocks : 100 ,
242
+ changedBlocks : []int {2 , 4 , 7 , 10 , 13 , 14 , 30 , 65 },
243
+ blockMetadataType : csi .BlockMetadataType_VARIABLE_LENGTH ,
244
+ startingOffset : 9 * state .BlockSizeBytes ,
245
+ maxResult : 3 ,
246
+ expectedResponse : []* csi.BlockMetadata {
247
+ {
248
+ ByteOffset : 10 * state .BlockSizeBytes ,
249
+ SizeBytes : state .BlockSizeBytes ,
250
+ },
251
+ {
252
+ ByteOffset : 13 * state .BlockSizeBytes ,
253
+ SizeBytes : state .BlockSizeBytes * 2 ,
254
+ },
255
+ {
256
+ ByteOffset : 30 * state .BlockSizeBytes ,
257
+ SizeBytes : state .BlockSizeBytes ,
258
+ },
259
+ {
260
+ ByteOffset : 65 * state .BlockSizeBytes ,
261
+ SizeBytes : state .BlockSizeBytes ,
262
+ },
263
+ },
264
+ expectErr : false ,
265
+ },
214
266
}
215
267
216
268
for _ , tc := range testCases {
@@ -238,6 +290,7 @@ func TestGetChangedBlockMetadata(t *testing.T) {
238
290
MaxVolumeSize : 1024 * 1024 * 1024 * 1024 ,
239
291
EnableTopology : true ,
240
292
EnableControllerModifyVolume : true ,
293
+ SnapshotMetadataBlockType : tc .blockMetadataType ,
241
294
}
242
295
243
296
hp , err := NewHostPathDriver (cfg )
@@ -322,12 +375,13 @@ func modifyBlock(t *testing.T, file *os.File, blockNumber int, newContent []byte
322
375
323
376
func TestGetAllocatedBlockMetadata (t * testing.T ) {
324
377
testCases := []struct {
325
- name string
326
- fileBlocks int
327
- startingOffset int64
328
- maxResult int32
329
- expectedBlocks []int
330
- expectErr bool
378
+ name string
379
+ fileBlocks int
380
+ startingOffset int64
381
+ blockMetadataType csi.BlockMetadataType
382
+ maxResult int32
383
+ expectedBlocks []int
384
+ expectErr bool
331
385
}{
332
386
{
333
387
name : "success case" ,
@@ -350,6 +404,22 @@ func TestGetAllocatedBlockMetadata(t *testing.T) {
350
404
expectedBlocks : []int {4 , 5 , 6 , 7 , 8 , 9 },
351
405
maxResult : 3 ,
352
406
},
407
+ {
408
+ name : "success case with variable block types" ,
409
+ fileBlocks : 5 ,
410
+ blockMetadataType : csi .BlockMetadataType_VARIABLE_LENGTH ,
411
+ maxResult : 100 ,
412
+ expectedBlocks : []int {0 },
413
+ expectErr : false ,
414
+ },
415
+ {
416
+ name : "success case with starting offset and variable length" ,
417
+ fileBlocks : 10 ,
418
+ startingOffset : 4 * state .BlockSizeBytes ,
419
+ blockMetadataType : csi .BlockMetadataType_VARIABLE_LENGTH ,
420
+ expectedBlocks : []int {4 },
421
+ maxResult : 10 ,
422
+ },
353
423
}
354
424
355
425
for _ , tc := range testCases {
@@ -371,6 +441,7 @@ func TestGetAllocatedBlockMetadata(t *testing.T) {
371
441
MaxVolumeSize : 1024 * 1024 * 1024 * 1024 ,
372
442
EnableTopology : true ,
373
443
EnableControllerModifyVolume : true ,
444
+ SnapshotMetadataBlockType : tc .blockMetadataType ,
374
445
}
375
446
376
447
hp , err := NewHostPathDriver (cfg )
@@ -403,6 +474,14 @@ func TestGetAllocatedBlockMetadata(t *testing.T) {
403
474
if len (tc .expectedBlocks ) != len (response ) {
404
475
t .Fatalf ("expected %d changed blocks metadata, got: %d" , tc .fileBlocks , len (response ))
405
476
}
477
+ if tc .blockMetadataType == csi .BlockMetadataType_VARIABLE_LENGTH {
478
+ expCB := createBlockMetadata (int64 (tc .expectedBlocks [0 ]), state .BlockSizeBytes )
479
+ expCB .SizeBytes = int64 (tc .fileBlocks - tc .expectedBlocks [0 ]) * state .BlockSizeBytes
480
+ if response [0 ].String () != expCB .String () {
481
+ t .Fatalf ("received unexpected block metadata, expected: %s\n , got %s" , expCB .String (), response [0 ].String ())
482
+ }
483
+ return
484
+ }
406
485
for i := 0 ; i < len (tc .expectedBlocks ); i ++ {
407
486
expCB := createBlockMetadata (int64 (tc .expectedBlocks [i ]), state .BlockSizeBytes )
408
487
if response [i ].String () != expCB .String () {
0 commit comments