@@ -25,13 +25,15 @@ import (
25
25
26
26
func TestExtractAndDefaultParameters (t * testing.T ) {
27
27
tests := []struct {
28
- name string
29
- parameters map [string ]string
30
- labels map [string ]string
31
- enableStoragePools bool
32
- extraTags map [string ]string
33
- expectParams DiskParameters
34
- expectErr bool
28
+ name string
29
+ parameters map [string ]string
30
+ labels map [string ]string
31
+ enableStoragePools bool
32
+ enableDataCache bool
33
+ extraTags map [string ]string
34
+ expectParams DiskParameters
35
+ expectDataCacheParams DataCacheParameters
36
+ expectErr bool
35
37
}{
36
38
{
37
39
name : "defaults" ,
@@ -350,11 +352,58 @@ func TestExtractAndDefaultParameters(t *testing.T) {
350
352
labels : map [string ]string {},
351
353
expectErr : true ,
352
354
},
355
+ {
356
+ name : "data cache parameters - set default cache mode" ,
357
+ enableDataCache : true ,
358
+ parameters : map [string ]string {ParameterKeyType : "pd-balanced" , ParameterKeyReplicationType : "none" , ParameterKeyDiskEncryptionKmsKey : "foo/key" , ParameterKeyLabels : "key1=value1,key2=value2" , ParameterKeyDataCacheSize : "1234Gi" },
359
+ labels : map [string ]string {},
360
+ expectParams : DiskParameters {
361
+ DiskType : "pd-balanced" ,
362
+ ReplicationType : "none" ,
363
+ DiskEncryptionKMSKey : "foo/key" ,
364
+ Tags : map [string ]string {},
365
+ Labels : map [string ]string {
366
+ "key1" : "value1" ,
367
+ "key2" : "value2" ,
368
+ },
369
+ },
370
+ expectDataCacheParams : DataCacheParameters {
371
+ DataCacheMode : DataCacheModeWriteThrough ,
372
+ DataCacheSize : "1234" ,
373
+ },
374
+ },
375
+ {
376
+ name : "data cache parameters" ,
377
+ enableDataCache : true ,
378
+ parameters : map [string ]string {ParameterKeyType : "pd-balanced" , ParameterKeyReplicationType : "none" , ParameterKeyDiskEncryptionKmsKey : "foo/key" , ParameterKeyLabels : "key1=value1,key2=value2" , ParameterKeyDataCacheSize : "1234Gi" , ParameterKeyDataCacheMode : DataCacheModeWriteBack },
379
+ labels : map [string ]string {},
380
+ expectParams : DiskParameters {
381
+ DiskType : "pd-balanced" ,
382
+ ReplicationType : "none" ,
383
+ DiskEncryptionKMSKey : "foo/key" ,
384
+ Tags : map [string ]string {},
385
+ Labels : map [string ]string {
386
+ "key1" : "value1" ,
387
+ "key2" : "value2" ,
388
+ },
389
+ },
390
+ expectDataCacheParams : DataCacheParameters {
391
+ DataCacheMode : DataCacheModeWriteBack ,
392
+ DataCacheSize : "1234" ,
393
+ },
394
+ },
395
+ {
396
+ name : "data cache parameters - enableDataCache is false" ,
397
+ enableDataCache : false ,
398
+ parameters : map [string ]string {ParameterKeyType : "pd-balanced" , ParameterKeyReplicationType : "none" , ParameterKeyDiskEncryptionKmsKey : "foo/key" , ParameterKeyLabels : "key1=value1,key2=value2" , ParameterKeyDataCacheSize : "1234Gi" , ParameterKeyDataCacheMode : DataCacheModeWriteBack },
399
+ labels : map [string ]string {},
400
+ expectErr : true ,
401
+ },
353
402
}
354
403
355
404
for _ , tc := range tests {
356
405
t .Run (tc .name , func (t * testing.T ) {
357
- p , _ , err := ExtractAndDefaultParameters (tc .parameters , "testDriver" , tc .labels , tc .enableStoragePools , false , tc .extraTags )
406
+ p , d , err := ExtractAndDefaultParameters (tc .parameters , "testDriver" , tc .labels , tc .enableStoragePools , tc . enableDataCache , tc .extraTags )
358
407
if gotErr := err != nil ; gotErr != tc .expectErr {
359
408
t .Fatalf ("ExtractAndDefaultParameters(%+v) = %v; expectedErr: %v" , tc .parameters , err , tc .expectErr )
360
409
}
@@ -365,6 +414,10 @@ func TestExtractAndDefaultParameters(t *testing.T) {
365
414
if diff := cmp .Diff (p , tc .expectParams ); diff != "" {
366
415
t .Errorf ("ExtractAndDefaultParameters(%+v): -want, +got \n %s" , tc .parameters , diff )
367
416
}
417
+
418
+ if diff := cmp .Diff (d , tc .expectDataCacheParams ); diff != "" {
419
+ t .Errorf ("ExtractAndDefaultParameters(%+v): -want, +got \n %s" , tc .parameters , diff )
420
+ }
368
421
})
369
422
}
370
423
}
0 commit comments