From 6a567b4779dfbe6cbbc3dbdb74442626d0c8ce00 Mon Sep 17 00:00:00 2001 From: peefy Date: Tue, 30 Jul 2024 16:35:22 +0800 Subject: [PATCH] feat: add log message in the test report Signed-off-by: peefy --- pkg/tools/testing/reporter_test.go | 6 ++++-- pkg/tools/testing/testing.go | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/tools/testing/reporter_test.go b/pkg/tools/testing/reporter_test.go index 5e9d645f..2429551b 100644 --- a/pkg/tools/testing/reporter_test.go +++ b/pkg/tools/testing/reporter_test.go @@ -10,8 +10,9 @@ func TestPrettyReporter(t *testing.T) { result := TestResult{ Info: []TestCaseInfo{ { - Name: "test_foo", - Duration: 1024, + Name: "test_foo", + Duration: 1024, + LogMessage: "log message", }, { Name: "test_bar", @@ -30,6 +31,7 @@ func TestPrettyReporter(t *testing.T) { } exp := `test_foo: PASS (1ms) +log message test_bar: FAIL (2ms) Error: assert failed -------------------------------------------------------------------------------- diff --git a/pkg/tools/testing/testing.go b/pkg/tools/testing/testing.go index ca288e58..771b0864 100644 --- a/pkg/tools/testing/testing.go +++ b/pkg/tools/testing/testing.go @@ -40,6 +40,9 @@ func (t *TestCaseInfo) Skip() bool { func (t *TestCaseInfo) Format() string { status := fmt.Sprintf("%s: %s (%dms)", t.Name, t.StatusString(), t.Duration/1000) + if t.LogMessage != "" { + return fmt.Sprintf("%s\n%s", status, t.LogMessage) + } if t.Fail() { return fmt.Sprintf("%s\n%s", status, t.ErrMessage) }