From a12872dda600f3fc173d444434823a3db76b3eb6 Mon Sep 17 00:00:00 2001 From: Michael Feher Date: Tue, 5 Nov 2024 16:06:08 -0500 Subject: [PATCH] fix: loading default port --- cmd/root.go | 4 +++- cmd/root_test.go | 14 ++++++++++++++ .../algod.admin.token | 1 + .../config.json | 4 ++++ 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 cmd/testdata/Test_InitConfigWithAddressAndDefaultPort/algod.admin.token create mode 100644 cmd/testdata/Test_InitConfigWithAddressAndDefaultPort/config.json diff --git a/cmd/root.go b/cmd/root.go index 7d1ecf32..f50bc7a0 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -230,7 +230,9 @@ func initConfig() { } } - + if strings.Contains(algodConfig.EndpointAddress, ":0") { + algodConfig.EndpointAddress = strings.Replace(algodConfig.EndpointAddress, ":0", ":8080", 1) + } if loadedToken == "" { // Handle Token Path tokenPath := algorandData + "/algod.admin.token" diff --git a/cmd/root_test.go b/cmd/root_test.go index 9ca04f90..c1b3eb4a 100644 --- a/cmd/root_test.go +++ b/cmd/root_test.go @@ -62,3 +62,17 @@ func Test_InitConfigWithAddress(t *testing.T) { t.Fatal("Invalid Server") } } + +func Test_InitConfigWithAddressAndDefaultPort(t *testing.T) { + cwd, _ := os.Getwd() + t.Setenv("ALGORAND_DATA", cwd+"/testdata/Test_InitConfigWithAddressAndDefaultPort") + + 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_InitConfigWithAddressAndDefaultPort/algod.admin.token b/cmd/testdata/Test_InitConfigWithAddressAndDefaultPort/algod.admin.token new file mode 100644 index 00000000..71b7a719 --- /dev/null +++ b/cmd/testdata/Test_InitConfigWithAddressAndDefaultPort/algod.admin.token @@ -0,0 +1 @@ +aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \ No newline at end of file diff --git a/cmd/testdata/Test_InitConfigWithAddressAndDefaultPort/config.json b/cmd/testdata/Test_InitConfigWithAddressAndDefaultPort/config.json new file mode 100644 index 00000000..0e455f6b --- /dev/null +++ b/cmd/testdata/Test_InitConfigWithAddressAndDefaultPort/config.json @@ -0,0 +1,4 @@ +{ + "EndpointAddress": "255.255.255.255:0", + "OtherKey": "" +} \ No newline at end of file