Skip to content

Commit 6ea722e

Browse files
committed
Fix TestLogAndMetrics
- LogLevel is becoming case-sensitive since v0.22.0 is not created from the latest master. - Firecracker doesn't log any Debug messages in this test. So the test uses Info and Error levels instead. Signed-off-by: Kazuyoshi Kato <[email protected]>
1 parent cd2b036 commit 6ea722e

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

machine_test.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,10 +420,29 @@ func TestStartVMM(t *testing.T) {
420420
}
421421

422422
func TestLogAndMetrics(t *testing.T) {
423-
const logLevel = "DEBUG"
423+
tests := []struct {
424+
logLevel string
425+
quiet bool
426+
}{
427+
{logLevel: "Info", quiet: false},
428+
{logLevel: "Error", quiet: true},
429+
}
430+
for _, test := range tests {
431+
t.Run(test.logLevel, func(t *testing.T) {
432+
out := testLogAndMetrics(t, test.logLevel)
433+
if test.quiet {
434+
assert.Regexp(t, `^Running Firecracker v0\.\d+\.0`, out)
435+
} else {
436+
assert.Contains(t, string(out), ":"+strings.ToUpper(test.logLevel)+"]")
437+
}
438+
})
439+
}
440+
}
441+
442+
func testLogAndMetrics(t *testing.T, logLevel string) string {
424443
const vmID = "UserSuppliedVMID"
425444

426-
dir, err := ioutil.TempDir("", t.Name())
445+
dir, err := ioutil.TempDir("", strings.Replace(t.Name(), "/", "_", -1))
427446
require.NoError(t, err)
428447
defer os.RemoveAll(dir)
429448

@@ -476,7 +495,7 @@ func TestLogAndMetrics(t *testing.T) {
476495

477496
content, err := ioutil.ReadFile(cfg.LogPath)
478497
require.NoError(t, err)
479-
assert.Contains(t, string(content), "["+vmID+":"+logLevel+"]")
498+
return string(content)
480499
}
481500

482501
func TestStartVMMOnce(t *testing.T) {

0 commit comments

Comments
 (0)