-
Notifications
You must be signed in to change notification settings - Fork 4
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 #52 from yashviagrawal/develop
Appknox-Go: Region and Host functionality
- Loading branch information
Showing
4 changed files
with
144 additions
and
22 deletions.
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
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,57 @@ | ||
package helper | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestResolveHostAndRegion(t *testing.T) { | ||
hostMappings := GetHostMappings() | ||
|
||
tests := []struct { | ||
name string | ||
host string | ||
region string | ||
expectedHost string | ||
expectError bool | ||
errorMessage string | ||
}{ | ||
// Case: Both host and region are empty, should default to global | ||
{"Empty host and region", "", "", hostMappings["global"], false, ""}, | ||
|
||
// Case: Empty host, valid region | ||
{"Empty host, valid region", "", "global", hostMappings["global"], false, ""}, | ||
|
||
// Case: Empty host, invalid region | ||
{"Empty host, invalid region", "", "invalid-region", "", true, "Invalid region name: invalid-region. Available regions: global, saudi"}, | ||
|
||
// Case: Valid host, ignore region | ||
{"Valid host, ignore region", "http://custom-host.com", "global", "http://custom-host.com", false, ""}, | ||
|
||
// Case: Empty host, valid region 'saudi' | ||
{"Empty host, valid saudi region", "", "saudi", hostMappings["saudi"], false, ""}, | ||
|
||
// Case: Invalid host URL format | ||
{"Invalid host URL format", "invalid_url", "", "", true, "invalid host URL: invalid_url"}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
result, err := ResolveHostAndRegion(test.host, test.region, hostMappings) | ||
|
||
if (err != nil) != test.expectError { | ||
t.Errorf("Expected error: %v, got: %v", test.expectError, err) | ||
} | ||
|
||
if test.expectError && err != nil { | ||
if !strings.Contains(err.Error(), test.errorMessage) { | ||
t.Errorf("Expected error message: %v, got: %v", test.errorMessage, err.Error()) | ||
} | ||
} | ||
|
||
if result != test.expectedHost && !test.expectError { | ||
t.Errorf("Expected host: %s, got: %s", test.expectedHost, result) | ||
} | ||
}) | ||
} | ||
} |