@@ -135,8 +135,8 @@ func TestIsNoMatchError(t *testing.T) {
135135 }
136136}
137137
138- // Test IsDisconnectedOCP scenarios
139- func TestIsDisconnectedOCP_WithICSP (t * testing.T ) {
138+ // Test HasMirrorRegistries scenarios
139+ func TestHasMirrorRegistries_WithICSP (t * testing.T ) {
140140 g := NewWithT (t )
141141 ctx := context .Background ()
142142
@@ -157,12 +157,12 @@ func TestIsDisconnectedOCP_WithICSP(t *testing.T) {
157157
158158 h := setupTestHelper (true , icsp )
159159
160- disconnected , err := IsDisconnectedOCP (ctx , h )
160+ hasMirrors , err := HasMirrorRegistries (ctx , h )
161161 g .Expect (err ).ToNot (HaveOccurred ())
162- g .Expect (disconnected ).To (BeTrue (), "Should detect disconnected environment when ICSP exists" )
162+ g .Expect (hasMirrors ).To (BeTrue (), "Should detect mirror registries when ICSP exists" )
163163}
164164
165- func TestIsDisconnectedOCP_WithIDMS (t * testing.T ) {
165+ func TestHasMirrorRegistries_WithIDMS (t * testing.T ) {
166166 g := NewWithT (t )
167167 ctx := context .Background ()
168168
@@ -185,12 +185,12 @@ func TestIsDisconnectedOCP_WithIDMS(t *testing.T) {
185185
186186 h := setupTestHelper (true , idms )
187187
188- disconnected , err := IsDisconnectedOCP (ctx , h )
188+ hasMirrors , err := HasMirrorRegistries (ctx , h )
189189 g .Expect (err ).ToNot (HaveOccurred ())
190- g .Expect (disconnected ).To (BeTrue (), "Should detect disconnected environment when IDMS exists" )
190+ g .Expect (hasMirrors ).To (BeTrue (), "Should detect mirror registries when IDMS exists" )
191191}
192192
193- func TestIsDisconnectedOCP_WithBothICSPAndIDMS (t * testing.T ) {
193+ func TestHasMirrorRegistries_WithBothICSPAndIDMS (t * testing.T ) {
194194 g := NewWithT (t )
195195 ctx := context .Background ()
196196
@@ -208,33 +208,33 @@ func TestIsDisconnectedOCP_WithBothICSPAndIDMS(t *testing.T) {
208208
209209 h := setupTestHelper (true , icsp , idms )
210210
211- disconnected , err := IsDisconnectedOCP (ctx , h )
211+ hasMirrors , err := HasMirrorRegistries (ctx , h )
212212 g .Expect (err ).ToNot (HaveOccurred ())
213- g .Expect (disconnected ).To (BeTrue (), "Should detect disconnected environment when both ICSP and IDMS exist" )
213+ g .Expect (hasMirrors ).To (BeTrue (), "Should detect mirror registries when both ICSP and IDMS exist" )
214214}
215215
216- func TestIsDisconnectedOCP_EmptyLists (t * testing.T ) {
216+ func TestHasMirrorRegistries_EmptyLists (t * testing.T ) {
217217 g := NewWithT (t )
218218 ctx := context .Background ()
219219
220220 // No ICSP or IDMS resources, but CRDs are registered
221221 h := setupTestHelper (true )
222222
223- disconnected , err := IsDisconnectedOCP (ctx , h )
223+ hasMirrors , err := HasMirrorRegistries (ctx , h )
224224 g .Expect (err ).ToNot (HaveOccurred ())
225- g .Expect (disconnected ).To (BeFalse (), "Should not detect disconnected environment when lists are empty" )
225+ g .Expect (hasMirrors ).To (BeFalse (), "Should not detect mirror registries when lists are empty" )
226226}
227227
228- func TestIsDisconnectedOCP_CRDsNotInstalled (t * testing.T ) {
228+ func TestHasMirrorRegistries_CRDsNotInstalled (t * testing.T ) {
229229 g := NewWithT (t )
230230 ctx := context .Background ()
231231
232232 // Don't register OpenShift CRDs - simulates non-OpenShift cluster
233233 h := setupTestHelper (false )
234234
235- disconnected , err := IsDisconnectedOCP (ctx , h )
235+ hasMirrors , err := HasMirrorRegistries (ctx , h )
236236 g .Expect (err ).ToNot (HaveOccurred (), "Should not return error when CRDs don't exist" )
237- g .Expect (disconnected ).To (BeFalse (), "Should return false when CRDs don't exist (graceful degradation)" )
237+ g .Expect (hasMirrors ).To (BeFalse (), "Should return false when CRDs don't exist (graceful degradation)" )
238238}
239239
240240// Test GetMCRegistryConf scenarios
@@ -290,7 +290,7 @@ func TestGetMCRegistryConf_MachineConfigNotFound(t *testing.T) {
290290 // MachineConfig CRD is registered but no resource exists
291291 // This simulates the case where MCO is installed but the specific
292292 // registry MachineConfig doesn't exist - this should be treated as an error,
293- // not a warning, because if MCO is present and disconnected env is detected,
293+ // not a warning, because if MCO is present and mirror registries are detected,
294294 // the registry config should exist.
295295 h := setupTestHelper (true )
296296
@@ -412,11 +412,11 @@ func TestGetMCRegistryConf_InvalidBase64Content(t *testing.T) {
412412}
413413
414414// Test real-world scenarios
415- func TestDisconnectedEnvironment_FullScenario (t * testing.T ) {
415+ func TestMirrorRegistryEnvironment_FullScenario (t * testing.T ) {
416416 g := NewWithT (t )
417417 ctx := context .Background ()
418418
419- // Simulate a full disconnected environment with IDMS and MachineConfig
419+ // Simulate a mirror registry environment with IDMS and MachineConfig
420420 expectedConfig := `[[registry]]
421421 prefix = ""
422422 location = "registry.redhat.io/rhosp-dev-preview"
@@ -467,10 +467,10 @@ func TestDisconnectedEnvironment_FullScenario(t *testing.T) {
467467
468468 h := setupTestHelper (true , idms , machineConfig )
469469
470- // Check for disconnected environment
471- disconnected , err := IsDisconnectedOCP (ctx , h )
470+ // Check for mirror registries
471+ hasMirrors , err := HasMirrorRegistries (ctx , h )
472472 g .Expect (err ).ToNot (HaveOccurred ())
473- g .Expect (disconnected ).To (BeTrue ())
473+ g .Expect (hasMirrors ).To (BeTrue ())
474474
475475 // Get the registry configuration
476476 config , err := GetMCRegistryConf (ctx , h )
@@ -485,14 +485,62 @@ func TestNonOpenShiftCluster_GracefulDegradation(t *testing.T) {
485485 // Simulate a non-OpenShift Kubernetes cluster (no OpenShift CRDs registered)
486486 h := setupTestHelper (false )
487487
488- // IsDisconnectedOCP should return false without error
489- disconnected , err := IsDisconnectedOCP (ctx , h )
488+ // HasMirrorRegistries should return false without error
489+ hasMirrors , err := HasMirrorRegistries (ctx , h )
490490 g .Expect (err ).ToNot (HaveOccurred (), "Should gracefully handle missing CRDs" )
491- g .Expect (disconnected ).To (BeFalse ())
491+ g .Expect (hasMirrors ).To (BeFalse ())
492492
493493 // GetMCRegistryConf should return an error that can be identified as "CRD not found"
494494 config , err := GetMCRegistryConf (ctx , h )
495495 g .Expect (err ).To (HaveOccurred ())
496496 g .Expect (IsNoMatchError (err )).To (BeTrue (), "Error should indicate CRD is not installed" )
497497 g .Expect (config ).To (BeEmpty ())
498498}
499+
500+ func TestGetMirrorRegistryCACerts (t * testing.T ) {
501+ g := NewWithT (t )
502+ ctx := context .Background ()
503+
504+ imageConfig := & ocpidms.Image {
505+ ObjectMeta : metav1.ObjectMeta {Name : "cluster" },
506+ Spec : ocpidms.ImageSpec {AdditionalTrustedCA : ocpidms.ConfigMapNameReference {Name : "registry-cas" }},
507+ }
508+ caConfigMap := & k8s_corev1.ConfigMap {
509+ ObjectMeta : metav1.ObjectMeta {Name : "registry-cas" , Namespace : "openshift-config" },
510+ Data : map [string ]string {"mirror.example.com" : "-----BEGIN CERTIFICATE-----\n test\n -----END CERTIFICATE-----" },
511+ }
512+ h := setupTestHelper (true , imageConfig , caConfigMap )
513+ caCerts , err := GetMirrorRegistryCACerts (ctx , h )
514+ g .Expect (err ).ToNot (HaveOccurred ())
515+ g .Expect (caCerts ).To (HaveLen (1 ))
516+ g .Expect (caCerts ).To (HaveKey ("mirror.example.com" ))
517+
518+ imageConfigNoCA := & ocpidms.Image {
519+ ObjectMeta : metav1.ObjectMeta {Name : "cluster" },
520+ Spec : ocpidms.ImageSpec {},
521+ }
522+ h = setupTestHelper (true , imageConfigNoCA )
523+ caCerts , err = GetMirrorRegistryCACerts (ctx , h )
524+ g .Expect (err ).ToNot (HaveOccurred ())
525+ g .Expect (caCerts ).To (BeNil ())
526+
527+ h = setupTestHelper (false )
528+ caCerts , err = GetMirrorRegistryCACerts (ctx , h )
529+ g .Expect (err ).ToNot (HaveOccurred ())
530+ g .Expect (caCerts ).To (BeNil ())
531+ }
532+
533+ func TestGetMirrorRegistryCACerts_ConfigMapNotFound (t * testing.T ) {
534+ g := NewWithT (t )
535+ ctx := context .Background ()
536+
537+ imageConfig := & ocpidms.Image {
538+ ObjectMeta : metav1.ObjectMeta {Name : "cluster" },
539+ Spec : ocpidms.ImageSpec {AdditionalTrustedCA : ocpidms.ConfigMapNameReference {Name : "non-existent-ca" }},
540+ }
541+ h := setupTestHelper (true , imageConfig )
542+
543+ caCerts , err := GetMirrorRegistryCACerts (ctx , h )
544+ g .Expect (err ).ToNot (HaveOccurred ())
545+ g .Expect (caCerts ).To (BeNil ())
546+ }
0 commit comments