Skip to content

Commit 5dbe6f2

Browse files
committed
TestAccDataSourceServerType_CompareWithPCU light version
1 parent 3a2cd75 commit 5dbe6f2

File tree

2 files changed

+1200
-21755
lines changed

2 files changed

+1200
-21755
lines changed

internal/services/instance/server_type_data_source_test.go

Lines changed: 53 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -121,60 +121,20 @@ func TestAccDataSourceServerType_CompareWithPCU(t *testing.T) {
121121
pcuAPI := product_catalog.NewPublicCatalogAPI(client)
122122
steps := []resource.TestStep(nil)
123123

124-
serversTypesToTestByZone := map[scw.Zone][]string{
125-
scw.ZoneFrPar1: {
126-
"COPARM1-2C-8G",
127-
"DEV1-M",
128-
"RENDER-S",
129-
"STARDUST1-S",
130-
},
131-
scw.ZoneFrPar2: {
132-
"COPARM1-32C-128G",
133-
"DEV1-L",
134-
"GP1-M",
135-
"H100-SXM-2-80G",
136-
"PLAY2-MICRO",
137-
},
138-
scw.ZoneFrPar3: {
139-
"GP1-S",
140-
"POP2-HM-16C-128G",
141-
"PRO2-XXS",
142-
},
143-
scw.ZoneNlAms1: {
144-
"COPARM1-8C-32G",
145-
"GP1-XL",
146-
"PRO2-XS",
147-
},
148-
scw.ZoneNlAms2: {
149-
"DEV1-XL",
150-
"POP2-HN-5",
151-
"PRO2-S",
152-
},
153-
scw.ZoneNlAms3: {
154-
"PLAY2-NANO",
155-
"POP2-2C-8G",
156-
"PRO2-L",
157-
},
158-
scw.ZonePlWaw1: {
159-
"DEV1-S",
160-
"GP1-L",
161-
"POP2-64C-256G",
162-
},
163-
scw.ZonePlWaw2: {
164-
"GP1-XS",
165-
"H100-1-80G",
166-
"L4-1-24G",
167-
"L40S-4-48G",
168-
},
169-
scw.ZonePlWaw3: {
170-
"PLAY2-PICO",
171-
"POP2-HC-32C-64G",
172-
"PRO2-M",
173-
},
124+
serverTypeToTestByZone := map[scw.Zone]string{
125+
scw.ZoneFrPar1: "RENDER-S",
126+
scw.ZoneFrPar2: "H100-SXM-2-80G",
127+
scw.ZoneFrPar3: "POP2-HM-16C-128G",
128+
scw.ZoneNlAms1: "COPARM1-8C-32G",
129+
scw.ZoneNlAms2: "DEV1-XL",
130+
scw.ZoneNlAms3: "PLAY2-NANO",
131+
scw.ZonePlWaw1: "GP1-L",
132+
scw.ZonePlWaw2: "L4-1-24G",
133+
scw.ZonePlWaw3: "PRO2-M",
174134
}
175135

176-
for zone, serverTypesToTest := range serversTypesToTestByZone {
177-
// List all available server types in selected zone
136+
for zone, serverTypeToTest := range serverTypeToTestByZone {
137+
// List all available server types in the zone to test
178138
pcuInstances, err := pcuAPI.ListPublicCatalogProducts(&product_catalog.PublicCatalogAPIListPublicCatalogProductsRequest{
179139
ProductTypes: []product_catalog.ListPublicCatalogProductsRequestProductType{
180140
product_catalog.ListPublicCatalogProductsRequestProductTypeInstance,
@@ -185,61 +145,59 @@ func TestAccDataSourceServerType_CompareWithPCU(t *testing.T) {
185145
t.Fatal(err)
186146
}
187147

188-
// Look for each server type to be tested in the zone in the PCU
189-
for _, serverTypeToTest := range serverTypesToTest {
190-
for _, pcuInstance := range pcuInstances.Products {
191-
if pcuInstance.Properties.Instance.OfferID != serverTypeToTest {
192-
continue
193-
}
148+
// Look for the server type to test in the PCU
149+
for _, pcuInstance := range pcuInstances.Products {
150+
if pcuInstance.Properties.Instance.OfferID != serverTypeToTest {
151+
continue
152+
}
194153

195-
// Fetch expected values from the PCU to be compared with the data source's info
196-
datasourceTFName := "data.scaleway_instance_server_type." + serverTypeToTest
197-
hardwareSpecs := pcuInstance.Properties.Hardware
154+
// Fetch expected values from the PCU to be compared with the data source's info
155+
datasourceTFName := "data.scaleway_instance_server_type." + serverTypeToTest
156+
hardwareSpecs := pcuInstance.Properties.Hardware
198157

199-
expectedArch := ""
158+
expectedArch := ""
200159

201-
switch hardwareSpecs.CPU.Arch {
202-
case product_catalog.PublicCatalogProductPropertiesHardwareCPUArchX64:
203-
expectedArch = instance.ArchX86_64.String()
204-
case product_catalog.PublicCatalogProductPropertiesHardwareCPUArchArm64:
205-
expectedArch = instance.ArchArm64.String()
206-
case product_catalog.PublicCatalogProductPropertiesHardwareCPUArchUnknownArch:
207-
expectedArch = instance.ArchUnknownArch.String()
208-
}
160+
switch hardwareSpecs.CPU.Arch {
161+
case product_catalog.PublicCatalogProductPropertiesHardwareCPUArchX64:
162+
expectedArch = instance.ArchX86_64.String()
163+
case product_catalog.PublicCatalogProductPropertiesHardwareCPUArchArm64:
164+
expectedArch = instance.ArchArm64.String()
165+
case product_catalog.PublicCatalogProductPropertiesHardwareCPUArchUnknownArch:
166+
expectedArch = instance.ArchUnknownArch.String()
167+
}
209168

210-
expectedCPU := strconv.FormatUint(uint64(hardwareSpecs.CPU.Threads), 10)
211-
expectedRAM := hardwareSpecs.RAM.Size.String()
169+
expectedCPU := strconv.FormatUint(uint64(hardwareSpecs.CPU.Threads), 10)
170+
expectedRAM := hardwareSpecs.RAM.Size.String()
212171

213-
expectedGPU := "0"
214-
if hardwareSpecs.Gpu != nil {
215-
expectedGPU = strconv.FormatUint(uint64(hardwareSpecs.Gpu.Count), 10)
216-
}
172+
expectedGPU := "0"
173+
if hardwareSpecs.Gpu != nil {
174+
expectedGPU = strconv.FormatUint(uint64(hardwareSpecs.Gpu.Count), 10)
175+
}
217176

218-
expectedInternalBandwidth := strconv.FormatUint(hardwareSpecs.Network.InternalBandwidth, 10)
219-
expectedPublicBandwidth := strconv.FormatUint(hardwareSpecs.Network.PublicBandwidth, 10)
177+
expectedInternalBandwidth := strconv.FormatUint(hardwareSpecs.Network.InternalBandwidth, 10)
178+
expectedPublicBandwidth := strconv.FormatUint(hardwareSpecs.Network.PublicBandwidth, 10)
220179

221-
expectedHourlyPrice := strings.TrimPrefix(pcuInstance.Price.RetailPrice.String(), "€ ")
180+
expectedHourlyPrice := strings.TrimPrefix(pcuInstance.Price.RetailPrice.String(), "€ ")
222181

223-
// Create test step
224-
steps = append(steps, resource.TestStep{
225-
Config: fmt.Sprintf(`
182+
// Create test step
183+
steps = append(steps, resource.TestStep{
184+
Config: fmt.Sprintf(`
226185
data "scaleway_instance_server_type" "%[1]s" {
227186
name = "%[1]s"
228187
zone = "%[2]s"
229188
}`, serverTypeToTest, zone),
230-
Check: resource.ComposeTestCheckFunc(
231-
resource.TestCheckResourceAttr(datasourceTFName, "name", serverTypeToTest),
232-
resource.TestCheckResourceAttr(datasourceTFName, "zone", zone.String()),
233-
resource.TestCheckResourceAttr(datasourceTFName, "arch", expectedArch),
234-
resource.TestCheckResourceAttr(datasourceTFName, "cpu", expectedCPU),
235-
resource.TestCheckResourceAttr(datasourceTFName, "ram", expectedRAM),
236-
resource.TestCheckResourceAttr(datasourceTFName, "gpu", expectedGPU),
237-
resource.TestCheckResourceAttr(datasourceTFName, "network.0.internal_bandwidth", expectedInternalBandwidth),
238-
resource.TestCheckResourceAttr(datasourceTFName, "network.0.public_bandwidth", expectedPublicBandwidth),
239-
resource.TestCheckResourceAttr(datasourceTFName, "hourly_price", expectedHourlyPrice),
240-
),
241-
})
242-
}
189+
Check: resource.ComposeTestCheckFunc(
190+
resource.TestCheckResourceAttr(datasourceTFName, "name", serverTypeToTest),
191+
resource.TestCheckResourceAttr(datasourceTFName, "zone", zone.String()),
192+
resource.TestCheckResourceAttr(datasourceTFName, "arch", expectedArch),
193+
resource.TestCheckResourceAttr(datasourceTFName, "cpu", expectedCPU),
194+
resource.TestCheckResourceAttr(datasourceTFName, "ram", expectedRAM),
195+
resource.TestCheckResourceAttr(datasourceTFName, "gpu", expectedGPU),
196+
resource.TestCheckResourceAttr(datasourceTFName, "network.0.internal_bandwidth", expectedInternalBandwidth),
197+
resource.TestCheckResourceAttr(datasourceTFName, "network.0.public_bandwidth", expectedPublicBandwidth),
198+
resource.TestCheckResourceAttr(datasourceTFName, "hourly_price", expectedHourlyPrice),
199+
),
200+
})
243201
}
244202
}
245203

internal/services/instance/testdata/data-source-server-type-compare-with-pcu.cassette.yaml

Lines changed: 1147 additions & 21660 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)