@@ -189,3 +189,58 @@ func TestIsSuccessResponse(t *testing.T) {
189
189
assert .Equal (t , test .expectedError , realError , "[%s] expected: %v, saw: %v" , test .name , realError , test .expectedError )
190
190
}
191
191
}
192
+ func TestConvertResourceGroupNameToLower (t * testing.T ) {
193
+ tests := []struct {
194
+ desc string
195
+ resourceID string
196
+ expected string
197
+ expectError bool
198
+ }{
199
+ {
200
+ desc : "empty string should report error" ,
201
+ resourceID : "" ,
202
+ expectError : true ,
203
+ },
204
+ {
205
+ desc : "resourceID not in Azure format should report error" ,
206
+ resourceID : "invalid-id" ,
207
+ expectError : true ,
208
+ },
209
+ {
210
+ desc : "providerID not in Azure format should report error" ,
211
+ resourceID : "azure://invalid-id" ,
212
+ expectError : true ,
213
+ },
214
+ {
215
+ desc : "resource group name in VM providerID should be converted" ,
216
+ resourceID : "azure:///subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroupName/providers/Microsoft.Compute/virtualMachines/k8s-agent-AAAAAAAA-0" ,
217
+ expected : "azure:///subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myresourcegroupname/providers/Microsoft.Compute/virtualMachines/k8s-agent-AAAAAAAA-0" ,
218
+ },
219
+ {
220
+ desc : "resource group name in VM resourceID should be converted" ,
221
+ resourceID : "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroupName/providers/Microsoft.Compute/virtualMachines/k8s-agent-AAAAAAAA-0" ,
222
+ expected : "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myresourcegroupname/providers/Microsoft.Compute/virtualMachines/k8s-agent-AAAAAAAA-0" ,
223
+ },
224
+ {
225
+ desc : "resource group name in VMSS providerID should be converted" ,
226
+ resourceID : "azure:///subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroupName/providers/Microsoft.Compute/virtualMachineScaleSets/myScaleSetName/virtualMachines/156" ,
227
+ expected : "azure:///subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myresourcegroupname/providers/Microsoft.Compute/virtualMachineScaleSets/myScaleSetName/virtualMachines/156" ,
228
+ },
229
+ {
230
+ desc : "resource group name in VMSS resourceID should be converted" ,
231
+ resourceID : "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroupName/providers/Microsoft.Compute/virtualMachineScaleSets/myScaleSetName/virtualMachines/156" ,
232
+ expected : "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myresourcegroupname/providers/Microsoft.Compute/virtualMachineScaleSets/myScaleSetName/virtualMachines/156" ,
233
+ },
234
+ }
235
+
236
+ for _ , test := range tests {
237
+ real , err := convertResourceGroupNameToLower (test .resourceID )
238
+ if test .expectError {
239
+ assert .NotNil (t , err , test .desc )
240
+ continue
241
+ }
242
+
243
+ assert .Nil (t , err , test .desc )
244
+ assert .Equal (t , test .expected , real , test .desc )
245
+ }
246
+ }
0 commit comments