Skip to content

Commit

Permalink
Fix regression to loadTelemetryConfig introduced in 2.3.0 (algorand#1845
Browse files Browse the repository at this point in the history
)

As part of a refactoring effort in algorand#1709, a small bug was introduced that changed the intended behavior of `loadTelemetryConfig`. This PR restores the previous behavior and adds a unit test for that.
  • Loading branch information
tsachiherman authored and onetechnical committed Jan 20, 2021
1 parent bb8f204 commit 6b37d16
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion logging/telemetryConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@ func loadTelemetryConfig(path string) (TelemetryConfig, error) {
return createTelemetryConfig(), err
}
defer f.Close()
cfg := createTelemetryConfig()
var cfg TelemetryConfig
var marshaledConfig MarshalingTelemetryConfig
marshaledConfig.TelemetryConfig = createTelemetryConfig()
dec := json.NewDecoder(f)
err = dec.Decode(&marshaledConfig)
cfg = marshaledConfig.TelemetryConfig
Expand Down
12 changes: 12 additions & 0 deletions logging/telemetryConfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,15 @@ func Test_SanitizeTelemetryString(t *testing.T) {
require.Equal(t, test.expected, SanitizeTelemetryString(test.input, test.parts))
}
}

func TestLoadTelemetryConfig(t *testing.T) {
testLoggingConfigFileName := "../test/testdata/configs/logging/logging.config.test1"
tc, err := loadTelemetryConfig(testLoggingConfigFileName)
require.NoError(t, err)
require.Equal(t, true, tc.Enable)
// make sure the user name was loaded from the specified file
require.Equal(t, "test-user-name", tc.UserName)
// ensure we know how to default correctly if some of the fields in the configuration field aren't specified.
require.Equal(t, createTelemetryConfig().Password, tc.Password)

}
4 changes: 4 additions & 0 deletions test/testdata/configs/logging/logging.config.test1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"Enable": true,
"UserName": "test-user-name"
}

0 comments on commit 6b37d16

Please sign in to comment.