@@ -569,8 +569,14 @@ func TestInitServerUrl(t *testing.T) {
569569 t .Cleanup (func () {
570570 ResetConfig ()
571571 })
572+ initConfig := func () {
573+ ResetConfig ()
574+ tempDir := t .TempDir ()
575+ viper .Set ("ConfigDir" , tempDir )
576+ }
572577
573578 initDirectoryConfig := func () {
579+ initConfig ()
574580 viper .Set ("Director.MinStatResponse" , 1 )
575581 viper .Set ("Director.MaxStatResponse" , 4 )
576582 }
@@ -637,6 +643,7 @@ func TestInitServerUrl(t *testing.T) {
637643
638644 t .Run ("reg-url-default-to-web-url" , func (t * testing.T ) {
639645 // We respect the URL value set directly by others. Won't remove 443 port
646+ initConfig ()
640647 // If Server_ExternalWebUrl is not set, Federation_RegistryUrl defaults to https://<hostname>:<non-443-port>
641648 // In this case, the port is 443, so Federation_RegistryUrl = https://example.com
642649 viper .Set ("Server.Hostname" , mockHostname )
@@ -649,13 +656,15 @@ func TestInitServerUrl(t *testing.T) {
649656
650657 // If Server_ExternalWebUrl is explicitly set, Federation_RegistryUrl defaults to whatever it is
651658 // But 443 port is stripped if provided
659+ initConfig ()
652660 viper .Set ("Server.ExternalWebUrl" , mockWebUrlW443Port )
653661 err = InitServer (ctx , server_structs .RegistryType )
654662 require .NoError (t , err )
655663 fedInfo , err = GetFederation (ctx )
656664 require .NoError (t , err )
657665 assert .Equal (t , mockWebUrlWoPort , fedInfo .RegistryEndpoint )
658666
667+ initConfig ()
659668 viper .Set ("Server.ExternalWebUrl" , mockWebUrlWoPort )
660669 viper .Set ("Federation.RegistryUrl" , "https://example-registry.com" )
661670 err = InitServer (ctx , server_structs .RegistryType )
@@ -667,6 +676,7 @@ func TestInitServerUrl(t *testing.T) {
667676
668677 t .Run ("broker-url-default-to-web-url" , func (t * testing.T ) {
669678 // We respect the URL value set directly by others. Won't remove 443 port
679+ initConfig ()
670680 // If Server_ExternalWebUrl is not set, Federation_BrokerUrl defaults to https://<hostname>:<non-443-port>
671681 // In this case, the port is 443, so Federation_BrokerUrl = https://example.com
672682 viper .Set ("Server.Hostname" , mockHostname )
@@ -679,13 +689,15 @@ func TestInitServerUrl(t *testing.T) {
679689
680690 // If Server_ExternalWebUrl is explicitly set, Federation_BrokerUrl defaults to whatever it is
681691 // But 443 port is stripped if provided
692+ initConfig ()
682693 viper .Set ("Server.ExternalWebUrl" , mockWebUrlW443Port )
683694 err = InitServer (ctx , server_structs .BrokerType )
684695 require .NoError (t , err )
685696 fedInfo , err = GetFederation (ctx )
686697 require .NoError (t , err )
687698 assert .Equal (t , mockWebUrlWoPort , fedInfo .BrokerEndpoint )
688699
700+ initConfig ()
689701 viper .Set ("Server.ExternalWebUrl" , mockWebUrlWoPort )
690702 viper .Set ("Federation.BrokerUrl" , "https://example-registry.com" )
691703 err = InitServer (ctx , server_structs .BrokerType )
0 commit comments