Skip to content

Commit 938a3b0

Browse files
authored
fix(baremetal): add function tests IPAM (#3043)
* fix(baremetal): add function tests IPAM * fix: golangci-run
1 parent b10d9eb commit 938a3b0

File tree

2 files changed

+1742
-1410
lines changed

2 files changed

+1742
-1410
lines changed

internal/services/baremetal/server_test.go

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,8 +1031,7 @@ func TestAccServer_WithIPAMPrivateNetwork(t *testing.T) {
10311031
Check: resource.ComposeTestCheckFunc(
10321032
testAccCheckBaremetalServerExists(tt, "scaleway_baremetal_server.base"),
10331033
testAccCheckBaremetalServerHasPrivateNetwork(tt, "scaleway_baremetal_server.base"),
1034-
resource.TestCheckResourceAttrPair("scaleway_ipam_ip.ip01", "address", "data.scaleway_ipam_ips.base", "ips.0.address"),
1035-
resource.TestCheckResourceAttrPair("scaleway_ipam_ip.ip02", "address", "data.scaleway_ipam_ips.base", "ips.1.address"),
1034+
testIPAMIPs(tt, "scaleway_ipam_ip", "data.scaleway_ipam_ips.base"),
10361035
),
10371036
},
10381037
},
@@ -1256,3 +1255,42 @@ func testAccCheckBaremetalServerHasPrivateNetwork(tt *acctest.TestTools, n strin
12561255
return nil
12571256
}
12581257
}
1258+
1259+
func testIPAMIPs(_ *acctest.TestTools, ipamResourcePrefix, ipamDataSource string) resource.TestCheckFunc {
1260+
return func(s *terraform.State) error {
1261+
ipamData, ok := s.RootModule().Resources[ipamDataSource]
1262+
if !ok {
1263+
return fmt.Errorf("not found: %s", ipamDataSource)
1264+
}
1265+
1266+
ips := ipamData.Primary.Attributes
1267+
expectedIPs := make(map[string]bool)
1268+
1269+
for i := 0; ; i++ {
1270+
key := fmt.Sprintf("ips.%d.address", i)
1271+
1272+
ip, ok := ips[key]
1273+
if !ok {
1274+
break
1275+
}
1276+
1277+
expectedIPs[ip] = true
1278+
}
1279+
1280+
for y := 1; ; y++ {
1281+
resourceName := fmt.Sprintf("%s.ip0%d", ipamResourcePrefix, y)
1282+
1283+
rs, ok := s.RootModule().Resources[resourceName]
1284+
if !ok {
1285+
break
1286+
}
1287+
1288+
ip := rs.Primary.Attributes["address"]
1289+
if !expectedIPs[ip] {
1290+
return fmt.Errorf("IP %q from resource %s not found in data source %s", ip, resourceName, ipamDataSource)
1291+
}
1292+
}
1293+
1294+
return nil
1295+
}
1296+
}

0 commit comments

Comments
 (0)