@@ -283,7 +283,7 @@ func TestListResourcesAzure(t *testing.T) {
283283 rtype : typeDisk ,
284284 name : diskName ,
285285 blocks : []string {toKey (typeResourceGroup , rgID )},
286- blocked : []string {toKey (typeVMScaleSetVM , vmID )},
286+ blocked : []string {toKey (typeVMScaleSet , vmssID )},
287287 },
288288 toKey (typeRoleAssignment , raID ): {
289289 rtype : typeRoleAssignment ,
@@ -307,6 +307,49 @@ func TestListResourcesAzure(t *testing.T) {
307307 }
308308}
309309
310+ func TestToDiskResource_ManagedBy (t * testing.T ) {
311+ g := resourceGetter {
312+ clusterInfo : resources.ClusterInfo {
313+ AzureSubscriptionID : "sub" ,
314+ AzureResourceGroupName : "rg" ,
315+ },
316+ }
317+
318+ diskID := "/subscriptions/sub/resourceGroups/rg/providers/Microsoft.Compute/disks/disk"
319+ diskName := "disk"
320+ vmssID := "/subscriptions/sub/resourceGroups/rg/providers/Microsoft.Compute/virtualMachineScaleSets/vmss"
321+
322+ tests := []struct {
323+ name string
324+ managedBy * string
325+ wantBlocked []string
326+ }{
327+ {
328+ name : "nil ManagedBy" ,
329+ managedBy : nil ,
330+ },
331+ {
332+ name : "valid ManagedBy blocks on parent VMSS" ,
333+ managedBy : to .Ptr (vmssID + "/virtualMachines/0" ),
334+ wantBlocked : []string {toKey (typeVMScaleSet , vmssID )},
335+ },
336+ }
337+
338+ for _ , tc := range tests {
339+ t .Run (tc .name , func (t * testing.T ) {
340+ disk := & compute.Disk {
341+ ID : to .Ptr (diskID ),
342+ Name : to .Ptr (diskName ),
343+ ManagedBy : tc .managedBy ,
344+ }
345+ r := g .toDiskResource (disk )
346+ if ! reflect .DeepEqual (r .Blocked , tc .wantBlocked ) {
347+ t .Errorf ("got Blocked=%v, want %v" , r .Blocked , tc .wantBlocked )
348+ }
349+ })
350+ }
351+ }
352+
310353func TestIsOwnedByCluster (t * testing.T ) {
311354 clusterName := "test-cluster"
312355
0 commit comments