Skip to content

Commit 2ad7c26

Browse files
committed
fixup! Add tests that fail when a worker topology name causes invalid Kubernetes resource name
Add tests to check package
1 parent c206457 commit 2ad7c26

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed

internal/topology/check/compatibility_test.go

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,66 @@ func TestMachineDeploymentTopologiesAreUniqueAndDefinedInClusterClass(t *testing
13331333
Build(),
13341334
wantErr: true,
13351335
},
1336+
{
1337+
name: "fail if MachineDeploymentTopology name is not a valid Kubernetes resource name",
1338+
clusterClass: builder.ClusterClass(metav1.NamespaceDefault, "class1").
1339+
WithInfrastructureClusterTemplate(
1340+
builder.InfrastructureClusterTemplate(metav1.NamespaceDefault, "infra1").Build()).
1341+
WithControlPlaneTemplate(
1342+
builder.ControlPlane(metav1.NamespaceDefault, "cp1").Build()).
1343+
WithControlPlaneInfrastructureMachineTemplate(
1344+
builder.InfrastructureMachineTemplate(metav1.NamespaceDefault, "cpinfra1").Build()).
1345+
WithWorkerMachineDeploymentClasses(
1346+
*builder.MachineDeploymentClass("aa").
1347+
WithInfrastructureTemplate(
1348+
builder.InfrastructureMachineTemplate(metav1.NamespaceDefault, "infra1").Build()).
1349+
WithBootstrapTemplate(
1350+
builder.BootstrapTemplate(metav1.NamespaceDefault, "bootstrap1").Build()).
1351+
Build()).
1352+
Build(),
1353+
cluster: builder.Cluster(metav1.NamespaceDefault, "cluster1").
1354+
WithTopology(
1355+
builder.ClusterTopology().
1356+
WithClass("class1").
1357+
WithVersion("v1.22.2").
1358+
WithMachineDeployment(
1359+
builder.MachineDeploymentTopology("under_score").
1360+
WithClass("aa").
1361+
Build()).
1362+
Build()).
1363+
Build(),
1364+
wantErr: true,
1365+
},
1366+
{
1367+
name: "fail if MachineDeploymentTopology name is not a valid Kubernetes label value",
1368+
clusterClass: builder.ClusterClass(metav1.NamespaceDefault, "class1").
1369+
WithInfrastructureClusterTemplate(
1370+
builder.InfrastructureClusterTemplate(metav1.NamespaceDefault, "infra1").Build()).
1371+
WithControlPlaneTemplate(
1372+
builder.ControlPlane(metav1.NamespaceDefault, "cp1").Build()).
1373+
WithControlPlaneInfrastructureMachineTemplate(
1374+
builder.InfrastructureMachineTemplate(metav1.NamespaceDefault, "cpinfra1").Build()).
1375+
WithWorkerMachineDeploymentClasses(
1376+
*builder.MachineDeploymentClass("aa").
1377+
WithInfrastructureTemplate(
1378+
builder.InfrastructureMachineTemplate(metav1.NamespaceDefault, "infra1").Build()).
1379+
WithBootstrapTemplate(
1380+
builder.BootstrapTemplate(metav1.NamespaceDefault, "bootstrap1").Build()).
1381+
Build()).
1382+
Build(),
1383+
cluster: builder.Cluster(metav1.NamespaceDefault, "cluster1").
1384+
WithTopology(
1385+
builder.ClusterTopology().
1386+
WithClass("class1").
1387+
WithVersion("v1.22.2").
1388+
WithMachineDeployment(
1389+
builder.MachineDeploymentTopology("forward/slash").
1390+
WithClass("aa").
1391+
Build()).
1392+
Build()).
1393+
Build(),
1394+
wantErr: true,
1395+
},
13361396
}
13371397
for _, tt := range tests {
13381398
t.Run(tt.name, func(t *testing.T) {
@@ -1540,6 +1600,66 @@ func TestMachinePoolTopologiesAreUniqueAndDefinedInClusterClass(t *testing.T) {
15401600
Build(),
15411601
wantErr: true,
15421602
},
1603+
{
1604+
name: "fail if MachinePoolTopology name is not a valid Kubernetes resource name",
1605+
clusterClass: builder.ClusterClass(metav1.NamespaceDefault, "class1").
1606+
WithInfrastructureClusterTemplate(
1607+
builder.InfrastructureClusterTemplate(metav1.NamespaceDefault, "infra1").Build()).
1608+
WithControlPlaneTemplate(
1609+
builder.ControlPlane(metav1.NamespaceDefault, "cp1").Build()).
1610+
WithControlPlaneInfrastructureMachineTemplate(
1611+
builder.InfrastructureMachinePoolTemplate(metav1.NamespaceDefault, "cpinfra1").Build()).
1612+
WithWorkerMachinePoolClasses(
1613+
*builder.MachinePoolClass("aa").
1614+
WithInfrastructureTemplate(
1615+
builder.InfrastructureMachinePoolTemplate(metav1.NamespaceDefault, "infra1").Build()).
1616+
WithBootstrapTemplate(
1617+
builder.BootstrapTemplate(metav1.NamespaceDefault, "bootstrap1").Build()).
1618+
Build()).
1619+
Build(),
1620+
cluster: builder.Cluster(metav1.NamespaceDefault, "cluster1").
1621+
WithTopology(
1622+
builder.ClusterTopology().
1623+
WithClass("class1").
1624+
WithVersion("v1.22.2").
1625+
WithMachinePool(
1626+
builder.MachinePoolTopology("under_score").
1627+
WithClass("aa").
1628+
Build()).
1629+
Build()).
1630+
Build(),
1631+
wantErr: true,
1632+
},
1633+
{
1634+
name: "fail if MachinePoolTopology name is not a valid Kubernetes label value",
1635+
clusterClass: builder.ClusterClass(metav1.NamespaceDefault, "class1").
1636+
WithInfrastructureClusterTemplate(
1637+
builder.InfrastructureClusterTemplate(metav1.NamespaceDefault, "infra1").Build()).
1638+
WithControlPlaneTemplate(
1639+
builder.ControlPlane(metav1.NamespaceDefault, "cp1").Build()).
1640+
WithControlPlaneInfrastructureMachineTemplate(
1641+
builder.InfrastructureMachinePoolTemplate(metav1.NamespaceDefault, "cpinfra1").Build()).
1642+
WithWorkerMachinePoolClasses(
1643+
*builder.MachinePoolClass("aa").
1644+
WithInfrastructureTemplate(
1645+
builder.InfrastructureMachinePoolTemplate(metav1.NamespaceDefault, "infra1").Build()).
1646+
WithBootstrapTemplate(
1647+
builder.BootstrapTemplate(metav1.NamespaceDefault, "bootstrap1").Build()).
1648+
Build()).
1649+
Build(),
1650+
cluster: builder.Cluster(metav1.NamespaceDefault, "cluster1").
1651+
WithTopology(
1652+
builder.ClusterTopology().
1653+
WithClass("class1").
1654+
WithVersion("v1.22.2").
1655+
WithMachinePool(
1656+
builder.MachinePoolTopology("forward/slash").
1657+
WithClass("aa").
1658+
Build()).
1659+
Build()).
1660+
Build(),
1661+
wantErr: true,
1662+
},
15431663
}
15441664
for _, tt := range tests {
15451665
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)