diff --git a/cmd/root.go b/cmd/root.go index 8e4402ca..7d1ecf32 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -214,7 +214,7 @@ func initConfig() { // Check for endpoint address if hasWildcardEndpointUrl(algodConfig.EndpointAddress) { algodConfig.EndpointAddress = replaceEndpointUrl(algodConfig.EndpointAddress) - } else { + } else if algodConfig.EndpointAddress == "" { // Assume it is not set, try to discover the port from the network file networkPath := algorandData + "/algod.net" networkFile, err := os.Open(networkPath) @@ -245,7 +245,7 @@ func initConfig() { } // Set the server configuration - viper.Set("server", "http://"+algodConfig.EndpointAddress) + viper.Set("server", "http://"+strings.Replace(algodConfig.EndpointAddress, "\n", "", 1)) viper.Set("data", dataConfigPath) } diff --git a/cmd/root_test.go b/cmd/root_test.go index cff94e1a..9ca04f90 100644 --- a/cmd/root_test.go +++ b/cmd/root_test.go @@ -48,3 +48,17 @@ func Test_InitConfigWithoutEndpoint(t *testing.T) { t.Fatal("Invalid Server") } } + +func Test_InitConfigWithAddress(t *testing.T) { + cwd, _ := os.Getwd() + t.Setenv("ALGORAND_DATA", cwd+"/testdata/Test_InitConfigWithAddress") + + initConfig() + server := viper.Get("server") + if server == "" { + t.Fatal("Invalid Server") + } + if server != "http://255.255.255.255:8080" { + t.Fatal("Invalid Server") + } +} diff --git a/cmd/testdata/Test_InitConfigWithAddress/algod.admin.token b/cmd/testdata/Test_InitConfigWithAddress/algod.admin.token new file mode 100644 index 00000000..71b7a719 --- /dev/null +++ b/cmd/testdata/Test_InitConfigWithAddress/algod.admin.token @@ -0,0 +1 @@ +aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \ No newline at end of file diff --git a/cmd/testdata/Test_InitConfigWithAddress/config.json b/cmd/testdata/Test_InitConfigWithAddress/config.json new file mode 100644 index 00000000..f172cd52 --- /dev/null +++ b/cmd/testdata/Test_InitConfigWithAddress/config.json @@ -0,0 +1,4 @@ +{ + "EndpointAddress": "255.255.255.255:8080", + "OtherKey": "" +} \ No newline at end of file