@@ -25,79 +25,105 @@ func TestExtractAndDefaultParameters(t *testing.T) {
25
25
tests := []struct {
26
26
name string
27
27
parameters map [string ]string
28
+ labels map [string ]string
28
29
expectParams DiskParameters
29
30
expectErr bool
30
31
}{
31
32
{
32
33
name : "defaults" ,
33
34
parameters : map [string ]string {},
35
+ labels : map [string ]string {},
34
36
expectParams : DiskParameters {
35
37
DiskType : "pd-standard" ,
36
38
ReplicationType : "none" ,
37
39
DiskEncryptionKMSKey : "" ,
38
40
Tags : make (map [string ]string ),
41
+ Labels : make (map [string ]string ),
39
42
},
40
43
},
41
44
{
42
45
name : "specified empties" ,
43
46
parameters : map [string ]string {ParameterKeyType : "" , ParameterKeyReplicationType : "" , ParameterKeyDiskEncryptionKmsKey : "" },
47
+ labels : map [string ]string {},
44
48
expectParams : DiskParameters {
45
49
DiskType : "pd-standard" ,
46
50
ReplicationType : "none" ,
47
51
DiskEncryptionKMSKey : "" ,
48
52
Tags : make (map [string ]string ),
53
+ Labels : make (map [string ]string ),
49
54
},
50
55
},
51
56
{
52
57
name : "random keys" ,
53
58
parameters : map [string ]string {ParameterKeyType : "" , "foo" : "" , ParameterKeyDiskEncryptionKmsKey : "" },
59
+ labels : map [string ]string {},
54
60
expectErr : true ,
55
61
},
56
62
{
57
63
name : "real values" ,
58
64
parameters : map [string ]string {ParameterKeyType : "pd-ssd" , ParameterKeyReplicationType : "regional-pd" , ParameterKeyDiskEncryptionKmsKey : "foo/key" },
65
+ labels : map [string ]string {},
59
66
expectParams : DiskParameters {
60
67
DiskType : "pd-ssd" ,
61
68
ReplicationType : "regional-pd" ,
62
69
DiskEncryptionKMSKey : "foo/key" ,
63
70
Tags : make (map [string ]string ),
71
+ Labels : make (map [string ]string ),
64
72
},
65
73
},
66
74
{
67
75
name : "real values, checking balanced pd" ,
68
76
parameters : map [string ]string {ParameterKeyType : "pd-balanced" , ParameterKeyReplicationType : "regional-pd" , ParameterKeyDiskEncryptionKmsKey : "foo/key" },
77
+ labels : map [string ]string {},
69
78
expectParams : DiskParameters {
70
79
DiskType : "pd-balanced" ,
71
80
ReplicationType : "regional-pd" ,
72
81
DiskEncryptionKMSKey : "foo/key" ,
73
82
Tags : make (map [string ]string ),
83
+ Labels : make (map [string ]string ),
74
84
},
75
85
},
76
86
{
77
87
name : "partial spec" ,
78
88
parameters : map [string ]string {ParameterKeyDiskEncryptionKmsKey : "foo/key" },
89
+ labels : map [string ]string {},
79
90
expectParams : DiskParameters {
80
91
DiskType : "pd-standard" ,
81
92
ReplicationType : "none" ,
82
93
DiskEncryptionKMSKey : "foo/key" ,
83
94
Tags : make (map [string ]string ),
95
+ Labels : make (map [string ]string ),
84
96
},
85
97
},
86
98
{
87
99
name : "tags" ,
88
100
parameters : map [string ]string {ParameterKeyPVCName : "testPVCName" , ParameterKeyPVCNamespace : "testPVCNamespace" , ParameterKeyPVName : "testPVName" },
101
+ labels : map [string ]string {},
89
102
expectParams : DiskParameters {
90
103
DiskType : "pd-standard" ,
91
104
ReplicationType : "none" ,
92
105
DiskEncryptionKMSKey : "" ,
93
106
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" },
94
120
},
95
121
},
96
122
}
97
123
98
124
for _ , tc := range tests {
99
125
t .Run (tc .name , func (t * testing.T ) {
100
- p , err := ExtractAndDefaultParameters (tc .parameters , "testDriver" )
126
+ p , err := ExtractAndDefaultParameters (tc .parameters , "testDriver" , tc . labels )
101
127
if gotErr := err != nil ; gotErr != tc .expectErr {
102
128
t .Fatalf ("ExtractAndDefaultParameters(%+v) = %v; expectedErr: %v" , tc .parameters , err , tc .expectErr )
103
129
}
0 commit comments