-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cspp): Fix PORT and BASE_URL behavior
Originally, if `CSPP_PORT` and the port found in `CSPP_BASE_URL` weren't the same, it would service on `CSPP_PORT` but link out and log with `CSPP_BASE_URL`. THis was bad. To fix this, we now honor the port found in `CSPP_BASE_URL` at all times, unless it's not set (e.g. it's just a string like `http://example.com/cspp`) and `CSPP_PORT` is set. Then it will use `CSPP_PORT` for all things. If neither is specified, it's just port 8080.
- Loading branch information
Michael Stahnke
committed
Feb 11, 2024
1 parent
7bb8b8e
commit 44afcba
Showing
3 changed files
with
109 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/spf13/viper" | ||
) | ||
|
||
// MockLogger is a mock logger for testing purposes | ||
type MockLogger struct{} | ||
|
||
func (l *MockLogger) Debugln(args ...interface{}) {} | ||
func (l *MockLogger) Errorln(args ...interface{}) {} | ||
|
||
func TestValidatePortVsBaseURL(t *testing.T) { | ||
// Mock configuration | ||
viper.Set("base_url", "http://example.com:8080") | ||
viper.Set("port", "8081") | ||
|
||
validatePortVsBaseURL() | ||
|
||
if port := viper.GetString("port"); port != "8080" { | ||
t.Errorf("Expected port to be set to 8080, got %s", port) | ||
} | ||
} | ||
|
||
func TestValidatePortVsBaseURL_NoBaseURL(t *testing.T) { | ||
// Mock configuration | ||
viper.Set("base_url", "") | ||
viper.Set("port", "8081") | ||
|
||
validatePortVsBaseURL() | ||
|
||
if port := viper.GetString("port"); port != "8081" { | ||
t.Errorf("Expected port to remain unchanged, got %s", port) | ||
} | ||
} | ||
|
||
func TestValidatePortVsBaseURL_InvalidBaseURL(t *testing.T) { | ||
// Mock configuration | ||
viper.Set("base_url", "invalid-url") | ||
viper.Set("port", "8081") | ||
|
||
validatePortVsBaseURL() | ||
|
||
// Expect the error message to be logged | ||
} | ||
|
||
func TestValidatePortVsBaseURL_BaseURLWithoutPort(t *testing.T) { | ||
// Mock configuration | ||
viper.Set("base_url", "http://example.com") | ||
viper.Set("port", "8081") | ||
|
||
validatePortVsBaseURL() | ||
|
||
if port := viper.GetString("port"); port != "8081" { | ||
t.Errorf("Expected port to remain unchanged, got %s", port) | ||
} | ||
} | ||
|
||
func TestValidatePortVsBaseURL_Port8080(t *testing.T) { | ||
// Mock configuration | ||
viper.Set("base_url", "http://example.com:8080") | ||
viper.Set("port", "8080") | ||
|
||
validatePortVsBaseURL() | ||
|
||
// Expect no message to be logged | ||
} | ||
|
||
func TestValidatePortVsBaseURL_CustomPort(t *testing.T) { | ||
// Mock configuration | ||
viper.Set("base_url", "http://example.com:9000") | ||
viper.Set("port", "8081") | ||
|
||
validatePortVsBaseURL() | ||
|
||
// Expect the overridden message to be logged | ||
} |