Skip to content

Commit

Permalink
Fixed config test where log file was hard coded. Test now constructs …
Browse files Browse the repository at this point in the history
…log file path based on current user.
  • Loading branch information
diamondap committed Oct 16, 2024
1 parent a311b3b commit c98a0ab
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions common/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 69,7 @@ func TestNewConfig(t *testing.T) {

jsonString, err := config.ToJSON()
require.NoError(t, err)
assert.Equal(t, expectedConfigJson, jsonString)
assert.Equal(t, GetExpectedConfigJson(), jsonString)
}

func TestConfigBucketQualifier(t *testing.T) {
Expand Down Expand Up @@ -145,6 145,9 @@ func TestHTTPScheme(t *testing.T) {
assert.Equal(t, "https", config.HTTPScheme())
}

// expectedConfigJson contains expected config JSON.
// Don't use this directly. Use GetExpectedConfigJSON instead
// because it substitutes '%s' with correct path.
var expectedConfigJson = `{
"Cookies": {
"Secure": {},
Expand All @@ -166,7 169,7 @@ var expectedConfigJson = `{
},
"EnvName": "test",
"Logging": {
"File": "/home/diamond/tmp/logs/registry_test.log",
"File": "%s",
"Level": 0,
"LogCaller": false,
"LogToConsole": false,
Expand Down Expand Up @@ -206,3 209,11 @@ var expectedConfigJson = `{
"MaintenanceMode": false,
"EmailServiceType": "SMTP"
}`

// GetExpectedConfigJson returns the expected config settings
// in JSON format. Note that it constructs the expected log file
// path based on the current user's home directory.
func GetExpectedConfigJson() string {
logFile, _ := common.ExpandTilde("~/tmp/logs/registry_test.log")
return fmt.Sprintf(expectedConfigJson, logFile)
}

0 comments on commit c98a0ab

Please sign in to comment.