@@ -531,15 +531,13 @@ func TestGetOCMConfigFromEnv(t *testing.T) {
531531 }
532532}
533533
534- // TestCreateConnectionWithUrl tests the CreateConnectionWithUrl function which creates
535- // an OCM SDK connection with a specified URL. It validates URL alias handling for
536- // 'production', 'staging', and 'integration' environments.
537- // Note: Successful connection creation requires valid OCM credentials and is tested
538- // in integration tests or the hive-login test command.
539- func TestCreateConnectionWithUrl (t * testing.T ) {
534+ // TestValidateAndResolveOcmUrl tests the ValidateAndResolveOcmUrl function which validates
535+ // and resolves OCM URL aliases without making any network calls. This is a pure validation test.
536+ func TestValidateAndResolveOcmUrl (t * testing.T ) {
540537 tests := []struct {
541538 name string
542539 ocmUrl string
540+ wantUrl string
543541 wantErr bool
544542 errContains string
545543 }{
@@ -558,43 +556,85 @@ func TestCreateConnectionWithUrl(t *testing.T) {
558556 errContains : "invalid OCM_URL found" ,
559557 },
560558 {
561- // Test that 'production' alias doesn't fail with "invalid alias" error
562- // Will fail with credentials error if not logged in, which is expected
559+ // Test that 'production' alias is correctly resolved
563560 name : "production alias recognized" ,
564561 ocmUrl : "production" ,
565- wantErr : true , // Will fail without credentials, but not with "invalid alias" error
562+ wantUrl : "https://api.openshift.com" ,
563+ wantErr : false ,
564+ },
565+ {
566+ // Test that 'prod' alias is correctly resolved
567+ name : "prod alias recognized" ,
568+ ocmUrl : "prod" ,
569+ wantUrl : "https://api.openshift.com" ,
570+ wantErr : false ,
566571 },
567572 {
568- // Test that 'staging' alias doesn't fail with "invalid alias" error
569- // Will fail with credentials error if not logged in, which is expected
573+ // Test that 'staging' alias is correctly resolved
570574 name : "staging alias recognized" ,
571575 ocmUrl : "staging" ,
572- wantErr : true , // Will fail without credentials, but not with "invalid alias" error
576+ wantUrl : "https://api.stage.openshift.com" ,
577+ wantErr : false ,
578+ },
579+ {
580+ // Test that 'stage' alias is correctly resolved
581+ name : "stage alias recognized" ,
582+ ocmUrl : "stage" ,
583+ wantUrl : "https://api.stage.openshift.com" ,
584+ wantErr : false ,
573585 },
574586 {
575- // Test that 'integration' alias doesn't fail with "invalid alias" error
576- // Will fail with credentials error if not logged in, which is expected
587+ // Test that 'integration' alias is correctly resolved
577588 name : "integration alias recognized" ,
578589 ocmUrl : "integration" ,
579- wantErr : true , // Will fail without credentials, but not with "invalid alias" error
590+ wantUrl : "https://api.integration.openshift.com" ,
591+ wantErr : false ,
592+ },
593+ {
594+ // Test that 'int' alias is correctly resolved
595+ name : "int alias recognized" ,
596+ ocmUrl : "int" ,
597+ wantUrl : "https://api.integration.openshift.com" ,
598+ wantErr : false ,
599+ },
600+ {
601+ // Test that full production URL is accepted
602+ name : "full production URL" ,
603+ ocmUrl : "https://api.openshift.com" ,
604+ wantUrl : "https://api.openshift.com" ,
605+ wantErr : false ,
606+ },
607+ {
608+ // Test that full staging URL is accepted
609+ name : "full staging URL" ,
610+ ocmUrl : "https://api.stage.openshift.com" ,
611+ wantUrl : "https://api.stage.openshift.com" ,
612+ wantErr : false ,
613+ },
614+ {
615+ // Test that gov cloud aliases are recognized
616+ name : "production gov alias recognized" ,
617+ ocmUrl : "productiongov" ,
618+ wantUrl : "https://api-admin.openshiftusgov.com" ,
619+ wantErr : false ,
580620 },
581621 }
582622
583623 for _ , tt := range tests {
584624 t .Run (tt .name , func (t * testing.T ) {
585- conn , err := CreateConnectionWithUrl (tt .ocmUrl )
625+ resolvedUrl , err := ValidateAndResolveOcmUrl (tt .ocmUrl )
586626 if tt .wantErr {
587627 if err == nil {
588- t .Errorf ("CreateConnectionWithUrl () expected error but got none" )
628+ t .Errorf ("ValidateAndResolveOcmUrl () expected error but got none" )
589629 } else if tt .errContains != "" && ! contains (err .Error (), tt .errContains ) {
590- t .Errorf ("CreateConnectionWithUrl () error = %v, want error containing %v" , err , tt .errContains )
630+ t .Errorf ("ValidateAndResolveOcmUrl () error = %v, want error containing %v" , err , tt .errContains )
591631 }
592632 } else {
593633 if err != nil {
594- t .Errorf ("CreateConnectionWithUrl () unexpected error = %v" , err )
634+ t .Errorf ("ValidateAndResolveOcmUrl () unexpected error = %v" , err )
595635 }
596- if conn != nil {
597- defer conn . Close ( )
636+ if resolvedUrl != tt . wantUrl {
637+ t . Errorf ( "ValidateAndResolveOcmUrl() = %v, want %v" , resolvedUrl , tt . wantUrl )
598638 }
599639 }
600640 })
0 commit comments