@@ -25,79 +25,105 @@ func TestExtractAndDefaultParameters(t *testing.T) {
2525 tests := []struct {
2626 name string
2727 parameters map [string ]string
28+ labels map [string ]string
2829 expectParams DiskParameters
2930 expectErr bool
3031 }{
3132 {
3233 name : "defaults" ,
3334 parameters : map [string ]string {},
35+ labels : map [string ]string {},
3436 expectParams : DiskParameters {
3537 DiskType : "pd-standard" ,
3638 ReplicationType : "none" ,
3739 DiskEncryptionKMSKey : "" ,
3840 Tags : make (map [string ]string ),
41+ Labels : make (map [string ]string ),
3942 },
4043 },
4144 {
4245 name : "specified empties" ,
4346 parameters : map [string ]string {ParameterKeyType : "" , ParameterKeyReplicationType : "" , ParameterKeyDiskEncryptionKmsKey : "" },
47+ labels : map [string ]string {},
4448 expectParams : DiskParameters {
4549 DiskType : "pd-standard" ,
4650 ReplicationType : "none" ,
4751 DiskEncryptionKMSKey : "" ,
4852 Tags : make (map [string ]string ),
53+ Labels : make (map [string ]string ),
4954 },
5055 },
5156 {
5257 name : "random keys" ,
5358 parameters : map [string ]string {ParameterKeyType : "" , "foo" : "" , ParameterKeyDiskEncryptionKmsKey : "" },
59+ labels : map [string ]string {},
5460 expectErr : true ,
5561 },
5662 {
5763 name : "real values" ,
5864 parameters : map [string ]string {ParameterKeyType : "pd-ssd" , ParameterKeyReplicationType : "regional-pd" , ParameterKeyDiskEncryptionKmsKey : "foo/key" },
65+ labels : map [string ]string {},
5966 expectParams : DiskParameters {
6067 DiskType : "pd-ssd" ,
6168 ReplicationType : "regional-pd" ,
6269 DiskEncryptionKMSKey : "foo/key" ,
6370 Tags : make (map [string ]string ),
71+ Labels : make (map [string ]string ),
6472 },
6573 },
6674 {
6775 name : "real values, checking balanced pd" ,
6876 parameters : map [string ]string {ParameterKeyType : "pd-balanced" , ParameterKeyReplicationType : "regional-pd" , ParameterKeyDiskEncryptionKmsKey : "foo/key" },
77+ labels : map [string ]string {},
6978 expectParams : DiskParameters {
7079 DiskType : "pd-balanced" ,
7180 ReplicationType : "regional-pd" ,
7281 DiskEncryptionKMSKey : "foo/key" ,
7382 Tags : make (map [string ]string ),
83+ Labels : make (map [string ]string ),
7484 },
7585 },
7686 {
7787 name : "partial spec" ,
7888 parameters : map [string ]string {ParameterKeyDiskEncryptionKmsKey : "foo/key" },
89+ labels : map [string ]string {},
7990 expectParams : DiskParameters {
8091 DiskType : "pd-standard" ,
8192 ReplicationType : "none" ,
8293 DiskEncryptionKMSKey : "foo/key" ,
8394 Tags : make (map [string ]string ),
95+ Labels : make (map [string ]string ),
8496 },
8597 },
8698 {
8799 name : "tags" ,
88100 parameters : map [string ]string {ParameterKeyPVCName : "testPVCName" , ParameterKeyPVCNamespace : "testPVCNamespace" , ParameterKeyPVName : "testPVName" },
101+ labels : map [string ]string {},
89102 expectParams : DiskParameters {
90103 DiskType : "pd-standard" ,
91104 ReplicationType : "none" ,
92105 DiskEncryptionKMSKey : "" ,
93106 Tags : map [string ]string {tagKeyCreatedForClaimName : "testPVCName" , tagKeyCreatedForClaimNamespace : "testPVCNamespace" , tagKeyCreatedForVolumeName : "testPVName" , tagKeyCreatedBy : "testDriver" },
107+ Labels : make (map [string ]string ),
108+ },
109+ },
110+ {
111+ name : "labels" ,
112+ parameters : map [string ]string {},
113+ labels : map [string ]string {"label-1" : "label-value-1" , "label-2" : "label-value-2" },
114+ expectParams : DiskParameters {
115+ DiskType : "pd-standard" ,
116+ ReplicationType : "none" ,
117+ DiskEncryptionKMSKey : "" ,
118+ Tags : map [string ]string {},
119+ Labels : map [string ]string {"label-1" : "label-value-1" , "label-2" : "label-value-2" },
94120 },
95121 },
96122 }
97123
98124 for _ , tc := range tests {
99125 t .Run (tc .name , func (t * testing.T ) {
100- p , err := ExtractAndDefaultParameters (tc .parameters , "testDriver" )
126+ p , err := ExtractAndDefaultParameters (tc .parameters , "testDriver" , tc . labels )
101127 if gotErr := err != nil ; gotErr != tc .expectErr {
102128 t .Fatalf ("ExtractAndDefaultParameters(%+v) = %v; expectedErr: %v" , tc .parameters , err , tc .expectErr )
103129 }
0 commit comments