@@ -1146,6 +1146,132 @@ func TestAddonReconcile(t *testing.T) {
1146
1146
if tc .matchStatus != nil {
1147
1147
g .Expect (cs .OCIManagedControlPlane .Status .AddonStatus ).To (Equal (tc .matchStatus ))
1148
1148
}
1149
+
1150
+ })
1151
+ }
1152
+ }
1153
+
1154
+ func TestCompareSpecs (t * testing.T ) {
1155
+ var (
1156
+ cs * ManagedControlPlaneScope
1157
+ mockCtrl * gomock.Controller
1158
+ )
1159
+
1160
+ setup := func (t * testing.T , g * WithT ) {
1161
+ mockCtrl = gomock .NewController (t )
1162
+ var err error
1163
+
1164
+ ociClusterAccessor := OCIManagedCluster {
1165
+ & infrastructurev1beta2.OCIManagedCluster {
1166
+ ObjectMeta : metav1.ObjectMeta {
1167
+ UID : "cluster_uid" ,
1168
+ },
1169
+ },
1170
+ }
1171
+
1172
+ cs , err = NewManagedControlPlaneScope (ManagedControlPlaneScopeParams {
1173
+ OCIManagedControlPlane : & infrastructurev1beta2.OCIManagedControlPlane {
1174
+ ObjectMeta : metav1.ObjectMeta {
1175
+ Name : "test" ,
1176
+ },
1177
+ Spec : infrastructurev1beta2.OCIManagedControlPlaneSpec {},
1178
+ },
1179
+ OCIClusterAccessor : ociClusterAccessor ,
1180
+ Cluster : & clusterv1.Cluster {
1181
+ ObjectMeta : metav1.ObjectMeta {
1182
+ Name : "test" ,
1183
+ Namespace : "default" ,
1184
+ },
1185
+ },
1186
+ })
1187
+ g .Expect (err ).To (BeNil ())
1188
+ }
1189
+
1190
+ teardown := func (t * testing.T , g * WithT ) {
1191
+ mockCtrl .Finish ()
1192
+ }
1193
+
1194
+ specWithFields := func (version , kms string , enableDashboard bool ) * infrastructurev1beta2.OCIManagedControlPlaneSpec {
1195
+ return & infrastructurev1beta2.OCIManagedControlPlaneSpec {
1196
+ Version : common .String (version ),
1197
+ KmsKeyId : common .String (kms ),
1198
+ ClusterOption : infrastructurev1beta2.ClusterOptions {
1199
+ AddOnOptions : & infrastructurev1beta2.AddOnOptions {
1200
+ IsKubernetesDashboardEnabled : common .Bool (enableDashboard ),
1201
+ },
1202
+ },
1203
+ ImagePolicyConfig : & infrastructurev1beta2.ImagePolicyConfig {
1204
+ IsPolicyEnabled : common .Bool (true ),
1205
+ KeyDetails : []infrastructurev1beta2.KeyDetails {{
1206
+ KmsKeyId : common .String ("image-kms-id" ),
1207
+ }},
1208
+ },
1209
+ ClusterPodNetworkOptions : []infrastructurev1beta2.ClusterPodNetworkOptions {
1210
+ {
1211
+ CniType : infrastructurev1beta2 .VCNNativeCNI ,
1212
+ },
1213
+ },
1214
+ }
1215
+ }
1216
+
1217
+ tests := []struct {
1218
+ name string
1219
+ spec1 * infrastructurev1beta2.OCIManagedControlPlaneSpec
1220
+ spec2 * infrastructurev1beta2.OCIManagedControlPlaneSpec
1221
+ expectedEqual bool
1222
+ }{
1223
+ {
1224
+ name : "both specs nil" ,
1225
+ spec1 : nil ,
1226
+ spec2 : nil ,
1227
+ expectedEqual : true ,
1228
+ },
1229
+ {
1230
+ name : "spec1 nil, spec2 not nil" ,
1231
+ spec1 : nil ,
1232
+ spec2 : specWithFields ("v1.27.2" , "kms1" , true ),
1233
+ expectedEqual : false ,
1234
+ },
1235
+ {
1236
+ name : "spec2 nil, spec1 not nil" ,
1237
+ spec1 : specWithFields ("v1.27.2" , "kms1" , true ),
1238
+ spec2 : nil ,
1239
+ expectedEqual : false ,
1240
+ },
1241
+ {
1242
+ name : "specs are equal" ,
1243
+ spec1 : specWithFields ("v1.27.2" , "kms1" , true ),
1244
+ spec2 : specWithFields ("v1.27.2" , "kms1" , true ),
1245
+ expectedEqual : true ,
1246
+ },
1247
+ {
1248
+ name : "specs differ in version" ,
1249
+ spec1 : specWithFields ("v1.27.2" , "kms1" , true ),
1250
+ spec2 : specWithFields ("v1.26.0" , "kms1" , true ),
1251
+ expectedEqual : false ,
1252
+ },
1253
+ {
1254
+ name : "specs differ in kmsKeyId" ,
1255
+ spec1 : specWithFields ("v1.27.2" , "kms1" , true ),
1256
+ spec2 : specWithFields ("v1.27.2" , "kms2" , true ),
1257
+ expectedEqual : false ,
1258
+ },
1259
+ {
1260
+ name : "specs differ in AddOnOptions" ,
1261
+ spec1 : specWithFields ("v1.27.2" , "kms1" , true ),
1262
+ spec2 : specWithFields ("v1.27.2" , "kms1" , false ),
1263
+ expectedEqual : false ,
1264
+ },
1265
+ }
1266
+
1267
+ for _ , tc := range tests {
1268
+ t .Run (tc .name , func (t * testing.T ) {
1269
+ g := NewWithT (t )
1270
+ defer teardown (t , g )
1271
+ setup (t , g )
1272
+
1273
+ equal := cs .compareSpecs (tc .spec1 , tc .spec2 )
1274
+ g .Expect (equal ).To (Equal (tc .expectedEqual ))
1149
1275
})
1150
1276
}
1151
1277
}
0 commit comments