@@ -26,6 +26,8 @@ import (
2626 capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2727)
2828
29+
30+
2931var _ = Describe ("Conversion" , func () {
3032 BeforeEach (func () { // Reset test vars to initial state.
3133 })
@@ -75,4 +77,83 @@ var _ = Describe("Conversion", func() {
7577 Ω (failureDomains ).Should (Equal (expectedResult ))
7678 })
7779 })
80+
81+ Context ("v1beta2 to v1beta1 function" , func () {
82+ It ("Converts v1beta2 cluster spec to v1beta1 zone based cluster spec" , func () {
83+ csCluster := & v1beta2.CloudStackCluster {
84+ ObjectMeta : metav1.ObjectMeta {
85+ Name : "cluster1" ,
86+ Namespace : "namespace1" ,
87+ },
88+ Spec : v1beta2.CloudStackClusterSpec {
89+ FailureDomains : []v1beta2.CloudStackFailureDomainSpec {
90+ {
91+ Name : "76472a84-d23f-4e97-b154-ee1b975ed936" ,
92+ Zone : v1beta2.CloudStackZoneSpec {
93+ ID : "76472a84-d23f-4e97-b154-ee1b975ed936" ,
94+ Network : v1beta2.Network {Name : "network1" },
95+ },
96+ Account : "account1" ,
97+ Domain : "domain1" ,
98+ ACSEndpoint : corev1.SecretReference {
99+ Name : "global" ,
100+ Namespace : "namespace1" ,
101+ },
102+ },
103+ },
104+ ControlPlaneEndpoint : capiv1.APIEndpoint {
105+ Host : "endpoint1" ,
106+ Port : 443 ,
107+ },
108+ },
109+ Status : v1beta2.CloudStackClusterStatus {},
110+ }
111+ converted := & v1beta1.CloudStackCluster {}
112+ err := v1beta1 .Convert_v1beta2_CloudStackCluster_To_v1beta1_CloudStackCluster (csCluster , converted , nil )
113+ expectedResult := & v1beta1.CloudStackCluster {
114+ ObjectMeta : metav1.ObjectMeta {
115+ Name : "cluster1" ,
116+ Namespace : "namespace1" ,
117+ },
118+ Spec : v1beta1.CloudStackClusterSpec {
119+ Zones : []v1beta1.Zone {
120+ {
121+ ID : "76472a84-d23f-4e97-b154-ee1b975ed936" ,
122+ Network : v1beta1.Network {
123+ Name : "network1" ,
124+ },
125+ },
126+ },
127+ ControlPlaneEndpoint : capiv1.APIEndpoint {
128+ Host : "endpoint1" ,
129+ Port : 443 ,
130+ },
131+ Account : "account1" ,
132+ Domain : "domain1" ,
133+ },
134+ Status : v1beta1.CloudStackClusterStatus {},
135+ }
136+
137+ Ω (err ).ShouldNot (HaveOccurred ())
138+ Ω (converted ).Should (Equal (expectedResult ))
139+ })
140+
141+ It ("Returns error when len(failureDomains) < 1" , func () {
142+ csCluster := & v1beta2.CloudStackCluster {
143+ ObjectMeta : metav1.ObjectMeta {
144+ Name : "cluster1" ,
145+ Namespace : "namespace1" ,
146+ },
147+ Spec : v1beta2.CloudStackClusterSpec {
148+ ControlPlaneEndpoint : capiv1.APIEndpoint {
149+ Host : "endpoint1" ,
150+ Port : 443 ,
151+ },
152+ },
153+ Status : v1beta2.CloudStackClusterStatus {},
154+ }
155+ err := v1beta1 .Convert_v1beta2_CloudStackCluster_To_v1beta1_CloudStackCluster (csCluster , nil , nil )
156+ Ω (err ).Should (HaveOccurred ())
157+ })
158+ })
78159})
0 commit comments