Skip to content

Commit 4f43968

Browse files
committed
Fix LoadConfig to correctly initialize DebugHelper
LogLevel must be read after json.Unmarshal(). Signed-off-by: Kazuyoshi Kato <[email protected]>
1 parent 31fa27b commit 4f43968

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

config/config.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,14 @@ func LoadConfig(path string) (*Config, error) {
9494
},
9595
}
9696

97+
if err := json.Unmarshal(data, cfg); err != nil {
98+
return nil, errors.Wrapf(err, "failed to unmarshal config from %q", path)
99+
}
100+
97101
cfg.DebugHelper, err = debug.New(cfg.LogLevels...)
98102
if err != nil {
99103
return nil, err
100104
}
101105

102-
if err := json.Unmarshal(data, cfg); err != nil {
103-
return nil, errors.Wrapf(err, "failed to unmarshal config from %q", path)
104-
}
105-
106106
return cfg, nil
107107
}

config/config_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ func TestLoadConfigOverrides(t *testing.T) {
4747
"kernel_image_path":"%s",
4848
"root_drive":"%s",
4949
"cpu_count": %d,
50-
"cpu_template": "%s"
50+
"cpu_template": "%s",
51+
"log_levels": ["debug"]
5152
}`, overrideKernelArgs, overrideKernelPath, overrideRootfsPath, overrideCPUCount, overrideCPUTemplate)
5253
configFile, cleanup := createTempConfig(t, configContent)
5354
defer cleanup()
@@ -58,6 +59,8 @@ func TestLoadConfigOverrides(t *testing.T) {
5859
assert.Equal(t, overrideKernelPath, cfg.KernelImagePath, "expected overridden kernel path")
5960
assert.Equal(t, overrideRootfsPath, cfg.RootDrive, "expected overridden rootfs path")
6061
assert.Equal(t, overrideCPUTemplate, cfg.CPUTemplate, "expected overridden CPU template")
62+
63+
assert.True(t, cfg.DebugHelper.LogFirecrackerOutput())
6164
}
6265

6366
func createTempConfig(t *testing.T, contents string) (string, func()) {

0 commit comments

Comments
 (0)