Correctly set log-level from config.toml

This change contains a bugfix where the log-level (if specified in the config.toml file)
would be assigned to config.Root instead of config.LogLevel.

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar 2022-01-14 10:25:43 +01:00
parent cf192169a8
commit ffd98424d8
2 changed files with 32 additions and 22 deletions

View File

@ -117,7 +117,7 @@ func (c tomlConfig) updateFromReader(cfg *Config, reader io.Reader) error {
}
if v, ok := section.GetStringFrom(toml, "log-level"); ok {
cfg.Root = v
cfg.LogLevel = v
}
}
return nil

View File

@ -87,9 +87,18 @@ func TestUpdateFromReader(t *testing.T) {
LogLevel: "info",
},
},
{
description: "log-level is set",
lines: []string{"nvidia-container-runtime.log-level=\"trace\""},
expected: &Config{
DebugFilePath: "/dev/null",
LogLevel: "trace",
},
},
}
for i, tc := range testCases {
for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
cfg := getDefaultConfig()
c := tomlConfig{
@ -108,11 +117,12 @@ func TestUpdateFromReader(t *testing.T) {
err := c.updateFromReader(cfg, reader)
if tc.expectedError {
require.Error(t, err, "%d: %v", i, tc.description)
require.Error(t, err)
} else {
require.NoError(t, err, "%d: %v", i, tc.description)
require.NoError(t, err)
}
require.EqualValues(t, tc.expected, cfg, "%d: %v", i, tc.description)
require.EqualValues(t, tc.expected, cfg)
})
}
}