|
| 1 | +package data |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v7" |
| 7 | +) |
| 8 | + |
| 9 | +func ptr[T any](v T) *T { return &v } |
| 10 | + |
| 11 | +// noLocalStorageAttached tests |
| 12 | + |
| 13 | +func TestNoLocalStorageAttached_NoTempDiskNoNvme(t *testing.T) { |
| 14 | + vm := &virtualMachine{MaxResourceVolumeMB: 0, NvmeDiskSizeInMiB: 0} |
| 15 | + if !vm.noLocalStorageAttached() { |
| 16 | + t.Error("expected true: VM with no temp disk and no NVMe should have no local storage") |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +func TestNoLocalStorageAttached_HasTempDisk(t *testing.T) { |
| 21 | + vm := &virtualMachine{MaxResourceVolumeMB: 512, NvmeDiskSizeInMiB: 0} |
| 22 | + if vm.noLocalStorageAttached() { |
| 23 | + t.Error("expected false: VM with temp disk should have local storage") |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +func TestNoLocalStorageAttached_HasNvmeDisk(t *testing.T) { |
| 28 | + // L-series bug case: MaxResourceVolumeMB=0 but NvmeDiskSizeInMiB>0 |
| 29 | + vm := &virtualMachine{MaxResourceVolumeMB: 0, NvmeDiskSizeInMiB: 5492736} |
| 30 | + if vm.noLocalStorageAttached() { |
| 31 | + t.Error("expected false: L-series VM with NVMe storage should have local storage") |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +func TestNoLocalStorageAttached_HasBoth(t *testing.T) { |
| 36 | + vm := &virtualMachine{MaxResourceVolumeMB: 512, NvmeDiskSizeInMiB: 5492736} |
| 37 | + if vm.noLocalStorageAttached() { |
| 38 | + t.Error("expected false: VM with both temp disk and NVMe should have local storage") |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +// resourceSKUToVirtualMachine parsing tests |
| 43 | + |
| 44 | +func TestResourceSKUToVirtualMachine_ParsesNvmeDiskSizeInMiB(t *testing.T) { |
| 45 | + sku := &armcompute.ResourceSKU{ |
| 46 | + ResourceType: ptr("virtualMachines"), |
| 47 | + Name: ptr("Standard_L8aos_v4"), |
| 48 | + Family: ptr("standardLasv4Family"), |
| 49 | + Capabilities: []*armcompute.ResourceSKUCapabilities{ |
| 50 | + {Name: ptr("NvmeDiskSizeInMiB"), Value: ptr("5492736")}, |
| 51 | + }, |
| 52 | + } |
| 53 | + vm := resourceSKUToVirtualMachine(sku) |
| 54 | + if vm == nil { |
| 55 | + t.Fatal("expected non-nil virtualMachine") |
| 56 | + } |
| 57 | + if vm.NvmeDiskSizeInMiB != 5492736 { |
| 58 | + t.Errorf("NvmeDiskSizeInMiB: got %d, want 5492736", vm.NvmeDiskSizeInMiB) |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +func TestResourceSKUToVirtualMachine_ParsesDiskControllerTypes(t *testing.T) { |
| 63 | + sku := &armcompute.ResourceSKU{ |
| 64 | + ResourceType: ptr("virtualMachines"), |
| 65 | + Name: ptr("Standard_L8aos_v4"), |
| 66 | + Family: ptr("standardLasv4Family"), |
| 67 | + Capabilities: []*armcompute.ResourceSKUCapabilities{ |
| 68 | + {Name: ptr("DiskControllerTypes"), Value: ptr("NVMe,SCSI")}, |
| 69 | + }, |
| 70 | + } |
| 71 | + vm := resourceSKUToVirtualMachine(sku) |
| 72 | + if vm == nil { |
| 73 | + t.Fatal("expected non-nil virtualMachine") |
| 74 | + } |
| 75 | + if len(vm.DiskControllerTypes) != 2 { |
| 76 | + t.Fatalf("DiskControllerTypes: got %v, want [NVMe SCSI]", vm.DiskControllerTypes) |
| 77 | + } |
| 78 | + if vm.DiskControllerTypes[0] != "NVMe" || vm.DiskControllerTypes[1] != "SCSI" { |
| 79 | + t.Errorf("DiskControllerTypes: got %v, want [NVMe SCSI]", vm.DiskControllerTypes) |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +func TestResourceSKUToVirtualMachine_NvmeDiskSizeDefaultsToZero(t *testing.T) { |
| 84 | + sku := &armcompute.ResourceSKU{ |
| 85 | + ResourceType: ptr("virtualMachines"), |
| 86 | + Name: ptr("Standard_D8as_v5"), |
| 87 | + Family: ptr("standardDasv5Family"), |
| 88 | + Capabilities: []*armcompute.ResourceSKUCapabilities{ |
| 89 | + {Name: ptr("MaxResourceVolumeMB"), Value: ptr("307200")}, |
| 90 | + }, |
| 91 | + } |
| 92 | + vm := resourceSKUToVirtualMachine(sku) |
| 93 | + if vm == nil { |
| 94 | + t.Fatal("expected non-nil virtualMachine") |
| 95 | + } |
| 96 | + if vm.NvmeDiskSizeInMiB != 0 { |
| 97 | + t.Errorf("NvmeDiskSizeInMiB: got %d, want 0 for non-NVMe SKU", vm.NvmeDiskSizeInMiB) |
| 98 | + } |
| 99 | +} |
| 100 | + |
| 101 | +// filterLocalStorage tests |
| 102 | + |
| 103 | +func TestFilterLocalStorage_DropsNvmeSizes(t *testing.T) { |
| 104 | + capabilities := map[string]*virtualMachine{ |
| 105 | + "Standard_D8as_v5": {MaxResourceVolumeMB: 0, NvmeDiskSizeInMiB: 0}, |
| 106 | + "Standard_L8aos_v4": {MaxResourceVolumeMB: 0, NvmeDiskSizeInMiB: 5492736}, |
| 107 | + } |
| 108 | + got, dropped, unknown := filterLocalStorage([]string{"Standard_D8as_v5", "Standard_L8aos_v4"}, capabilities) |
| 109 | + if len(got) != 1 || got[0] != "Standard_D8as_v5" { |
| 110 | + t.Errorf("filtered: got %v, want [Standard_D8as_v5]", got) |
| 111 | + } |
| 112 | + if len(dropped) != 1 || dropped[0] != "Standard_L8aos_v4" { |
| 113 | + t.Errorf("dropped: got %v, want [Standard_L8aos_v4]", dropped) |
| 114 | + } |
| 115 | + if len(unknown) != 0 { |
| 116 | + t.Errorf("unknown: got %v, want []", unknown) |
| 117 | + } |
| 118 | +} |
| 119 | + |
| 120 | +func TestFilterLocalStorage_DropsTempDiskSizes(t *testing.T) { |
| 121 | + capabilities := map[string]*virtualMachine{ |
| 122 | + "Standard_D4s_v3": {MaxResourceVolumeMB: 32768, NvmeDiskSizeInMiB: 0}, |
| 123 | + } |
| 124 | + got, dropped, unknown := filterLocalStorage([]string{"Standard_D4s_v3"}, capabilities) |
| 125 | + if len(got) != 0 { |
| 126 | + t.Errorf("filtered: got %v, want []", got) |
| 127 | + } |
| 128 | + if len(dropped) != 1 { |
| 129 | + t.Errorf("dropped: got %v, want [Standard_D4s_v3]", dropped) |
| 130 | + } |
| 131 | + if len(unknown) != 0 { |
| 132 | + t.Errorf("unknown: got %v, want []", unknown) |
| 133 | + } |
| 134 | +} |
| 135 | + |
| 136 | +func TestFilterLocalStorage_PassesCleanSizes(t *testing.T) { |
| 137 | + capabilities := map[string]*virtualMachine{ |
| 138 | + "Standard_D8as_v5": {MaxResourceVolumeMB: 0, NvmeDiskSizeInMiB: 0}, |
| 139 | + } |
| 140 | + got, dropped, unknown := filterLocalStorage([]string{"Standard_D8as_v5"}, capabilities) |
| 141 | + if len(got) != 1 { |
| 142 | + t.Errorf("filtered: got %v, want [Standard_D8as_v5]", got) |
| 143 | + } |
| 144 | + if len(dropped) != 0 { |
| 145 | + t.Errorf("dropped: got %v, want []", dropped) |
| 146 | + } |
| 147 | + if len(unknown) != 0 { |
| 148 | + t.Errorf("unknown: got %v, want []", unknown) |
| 149 | + } |
| 150 | +} |
| 151 | + |
| 152 | +func TestFilterLocalStorage_ReportsUnknownSizes(t *testing.T) { |
| 153 | + // Sizes absent from the catalog (typo, restricted SKU) must appear in unknown, |
| 154 | + // not silently disappear. |
| 155 | + capabilities := map[string]*virtualMachine{ |
| 156 | + "Standard_D8as_v5": {MaxResourceVolumeMB: 0, NvmeDiskSizeInMiB: 0}, |
| 157 | + } |
| 158 | + got, dropped, unknown := filterLocalStorage( |
| 159 | + []string{"Standard_D8as_v5", "Standard_Typo_v99"}, capabilities) |
| 160 | + if len(got) != 1 || got[0] != "Standard_D8as_v5" { |
| 161 | + t.Errorf("filtered: got %v, want [Standard_D8as_v5]", got) |
| 162 | + } |
| 163 | + if len(dropped) != 0 { |
| 164 | + t.Errorf("dropped: got %v, want []", dropped) |
| 165 | + } |
| 166 | + if len(unknown) != 1 || unknown[0] != "Standard_Typo_v99" { |
| 167 | + t.Errorf("unknown: got %v, want [Standard_Typo_v99]", unknown) |
| 168 | + } |
| 169 | +} |
| 170 | + |
| 171 | +// baseFeaturesSupported regression: L-series must be rejected |
| 172 | + |
| 173 | +func TestBaseFeaturesSupported_LSeriesWithNvmeIsRejected(t *testing.T) { |
| 174 | + vm := &virtualMachine{ |
| 175 | + MaxResourceVolumeMB: 0, |
| 176 | + NvmeDiskSizeInMiB: 5492736, |
| 177 | + AcceleratedNetworkingEnabled: true, |
| 178 | + PremiumIO: true, |
| 179 | + EncryptionAtHostSupported: true, |
| 180 | + HyperVGenerations: []string{"V1", "V2"}, |
| 181 | + } |
| 182 | + if vm.baseFeaturesSupported() { |
| 183 | + t.Error("expected false: L-series VM with NVMe storage must not pass baseFeaturesSupported") |
| 184 | + } |
| 185 | +} |
0 commit comments