-
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.
Merge pull request #55 from stahnma/issue48
Port and Test work
- Loading branch information
Showing
5 changed files
with
119 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
.env | ||
cspp |
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
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 | ||
} |