@@ -234,6 +234,97 @@ func TestUpdateOCMClusterSpec(t *testing.T) {
234234 g .Expect (updated ).To (BeTrue ())
235235 g .Expect (ocmSpec ).To (Equal (expectedOCMSpec ))
236236 })
237+
238+ // Test case 8: Channel explicitly set - use it directly
239+ t .Run ("Channel explicitly set" , func (t * testing.T ) {
240+ rosaControlPlane := & rosacontrolplanev1.ROSAControlPlane {
241+ Spec : rosacontrolplanev1.RosaControlPlaneSpec {
242+ Channel : "eus-4.18" ,
243+ ChannelGroup : rosacontrolplanev1 .Stable , // Different from channel, but channel takes precedence
244+ Version : "4.16.5" ,
245+ },
246+ }
247+
248+ mockCluster , _ := v1 .NewCluster ().
249+ Version (v1 .NewVersion ().
250+ ID ("4.16.5" ).
251+ ChannelGroup ("stable" )).
252+ Build ()
253+
254+ reconciler := & ROSAControlPlaneReconciler {}
255+ ocmSpec , updated := reconciler .updateOCMClusterSpec (rosaControlPlane , mockCluster )
256+
257+ g .Expect (updated ).To (BeTrue ())
258+ g .Expect (ocmSpec .Channel ).To (Equal ("eus-4.18" ))
259+ g .Expect (ocmSpec .ChannelGroup ).To (BeEmpty ())
260+ })
261+
262+ // Test case 9: ChannelGroup matches current - no update
263+ t .Run ("ChannelGroup matches current channel group - no update" , func (t * testing.T ) {
264+ rosaControlPlane := & rosacontrolplanev1.ROSAControlPlane {
265+ Spec : rosacontrolplanev1.RosaControlPlaneSpec {
266+ ChannelGroup : rosacontrolplanev1 .Stable ,
267+ Version : "4.16.5" ,
268+ },
269+ }
270+
271+ mockCluster , _ := v1 .NewCluster ().
272+ Version (v1 .NewVersion ().
273+ ID ("4.18.3" ).
274+ ChannelGroup ("stable" )).
275+ Build ()
276+
277+ reconciler := & ROSAControlPlaneReconciler {}
278+ ocmSpec , updated := reconciler .updateOCMClusterSpec (rosaControlPlane , mockCluster )
279+
280+ g .Expect (updated ).To (BeFalse ())
281+ g .Expect (ocmSpec .Channel ).To (BeEmpty ())
282+ g .Expect (ocmSpec .ChannelGroup ).To (BeEmpty ())
283+ })
284+
285+ // Test case 10: ChannelGroup changes - update channelGroup
286+ t .Run ("ChannelGroup changes from stable to eus" , func (t * testing.T ) {
287+ rosaControlPlane := & rosacontrolplanev1.ROSAControlPlane {
288+ Spec : rosacontrolplanev1.RosaControlPlaneSpec {
289+ ChannelGroup : rosacontrolplanev1 .Eus , // Changing from stable to eus
290+ Version : "4.16.5" ,
291+ },
292+ }
293+
294+ mockCluster , _ := v1 .NewCluster ().
295+ Version (v1 .NewVersion ().
296+ ID ("4.18.3" ).
297+ ChannelGroup ("stable" )).
298+ Build ()
299+
300+ reconciler := & ROSAControlPlaneReconciler {}
301+ ocmSpec , updated := reconciler .updateOCMClusterSpec (rosaControlPlane , mockCluster )
302+
303+ g .Expect (updated ).To (BeTrue ())
304+ g .Expect (ocmSpec .ChannelGroup ).To (Equal ("eus" ))
305+ g .Expect (ocmSpec .Channel ).To (BeEmpty ())
306+ })
307+
308+ // Test case 11: ChannelGroup set, no current version info
309+ t .Run ("ChannelGroup set with no current version info" , func (t * testing.T ) {
310+ rosaControlPlane := & rosacontrolplanev1.ROSAControlPlane {
311+ Spec : rosacontrolplanev1.RosaControlPlaneSpec {
312+ ChannelGroup : rosacontrolplanev1 .Eus ,
313+ Version : "4.16.5" ,
314+ },
315+ }
316+
317+ // Cluster has no version info (edge case)
318+ // When version is nil, we skip the channelGroup update
319+ mockCluster , _ := v1 .NewCluster ().Build ()
320+
321+ reconciler := & ROSAControlPlaneReconciler {}
322+ ocmSpec , updated := reconciler .updateOCMClusterSpec (rosaControlPlane , mockCluster )
323+
324+ g .Expect (updated ).To (BeFalse ())
325+ g .Expect (ocmSpec .ChannelGroup ).To (BeEmpty ())
326+ g .Expect (ocmSpec .Channel ).To (BeEmpty ())
327+ })
237328}
238329
239330func TestValidateControlPlaneSpec (t * testing.T ) {
@@ -455,6 +546,9 @@ func TestRosaControlPlaneReconcileStatusVersion(t *testing.T) {
455546 m .UpdateCluster (gomock .Any (), gomock .Any (), gomock .Any ()).DoAndReturn (func (clusterKey string , creator * rosaaws.Creator , config ocm.Spec ) error {
456547 return nil
457548 }).Times (1 )
549+ m .GetAvailableChannels (gomock .Any ()).DoAndReturn (func (versionID string ) ([]string , error ) {
550+ return []string {"stable-4.15" }, nil
551+ }).Times (1 )
458552 m .GetIdentityProviders (gomock .Any ()).DoAndReturn (func (cclusterID string ) ([]* v1.IdentityProvider , error ) {
459553 ip := []* v1.IdentityProvider {}
460554 return ip , nil
0 commit comments