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