Skip to content

Commit 1c7bb83

Browse files
mzazrivecserngawy
authored andcommitted
ROSANetwork: tests
1 parent a4ae03f commit 1c7bb83

File tree

5 files changed

+897
-3
lines changed

5 files changed

+897
-3
lines changed

config/crd/bases/infrastructure.cluster.x-k8s.io_rosanetworks.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.19.0
6+
controller-gen.kubebuilder.io/version: v0.17.3
77
name: rosanetworks.infrastructure.cluster.x-k8s.io
88
spec:
99
group: infrastructure.cluster.x-k8s.io
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1beta2
18+
19+
import (
20+
"testing"
21+
22+
. "github.com/onsi/gomega"
23+
corev1 "k8s.io/api/core/v1"
24+
)
25+
26+
func TestValidateROSANetwork(t *testing.T) {
27+
g := NewGomegaWithT(t)
28+
29+
rosaCP := &ROSAControlPlane{
30+
Spec: RosaControlPlaneSpec{},
31+
Status: RosaControlPlaneStatus{},
32+
}
33+
34+
t.Run("Validation error when no ROSANetworkRef, no subnets, no AZs", func(t *testing.T) {
35+
err := rosaCP.validateROSANetwork()
36+
g.Expect(err).To(HaveOccurred())
37+
g.Expect(err.Error()).To(ContainSubstring("spec.subnets cannot be empty"))
38+
})
39+
40+
t.Run("Validation error when no ROSANetworkRef, subnets present, no AZs", func(t *testing.T) {
41+
rosaCP.Spec.Subnets = []string{"subnet01", "subnet02"}
42+
err := rosaCP.validateROSANetwork()
43+
g.Expect(err).To(HaveOccurred())
44+
g.Expect(err.Error()).To(ContainSubstring("spec.availabilityZones cannot be empty"))
45+
})
46+
47+
t.Run("Validation succeeds when no ROSANetworkRef, subnets and AZs are present", func(t *testing.T) {
48+
rosaCP.Spec.AvailabilityZones = []string{"AZ01", "AZ02"}
49+
err := rosaCP.validateROSANetwork()
50+
g.Expect(err).NotTo(HaveOccurred())
51+
})
52+
53+
t.Run("Validation error when ROSANetworkRef, subnets and AZs are present", func(t *testing.T) {
54+
rosaCP.Spec.ROSANetworkRef = &corev1.LocalObjectReference{}
55+
err := rosaCP.validateROSANetwork()
56+
g.Expect(err).To(HaveOccurred())
57+
g.Expect(err.Error()).To(ContainSubstring("spec.subnets and spec.rosaNetworkRef are mutually exclusive"))
58+
})
59+
60+
t.Run("Validation error when ROSANetworkRef and subnets are present, no AZs", func(t *testing.T) {
61+
rosaCP.Spec.AvailabilityZones = nil
62+
err := rosaCP.validateROSANetwork()
63+
g.Expect(err).To(HaveOccurred())
64+
g.Expect(err.Error()).To(ContainSubstring("spec.subnets and spec.rosaNetworkRef are mutually exclusive"))
65+
})
66+
67+
t.Run("Validation error when ROSANetworkRef and AZs are present, no subnets", func(t *testing.T) {
68+
rosaCP.Spec.AvailabilityZones = []string{"AZ01", "AZ02"}
69+
rosaCP.Spec.Subnets = nil
70+
err := rosaCP.validateROSANetwork()
71+
g.Expect(err).To(HaveOccurred())
72+
g.Expect(err.Error()).To(ContainSubstring("spec.availabilityZones and spec.rosaNetworkRef are mutually exclusive"))
73+
})
74+
75+
t.Run("Validation succeeds when ROSANetworkRef is present, no subnets and no AZs", func(t *testing.T) {
76+
rosaCP.Spec.AvailabilityZones = nil
77+
rosaCP.Spec.Subnets = nil
78+
err := rosaCP.validateROSANetwork()
79+
g.Expect(err).NotTo(HaveOccurred())
80+
})
81+
}

0 commit comments

Comments
 (0)