Skip to content

Commit

Permalink
test: comment out slogtest.Run
Browse files Browse the repository at this point in the history
Signed-off-by: knqyf263 <[email protected]>
  • Loading branch information
knqyf263 committed Apr 8, 2024
1 parent d355d7c commit a6288d5
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions pkg/log/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"regexp"
"strings"
"testing"
"testing/slogtest"
"time"
)

Expand Down Expand Up @@ -126,29 +125,30 @@ func stripColorCodes(s string) string {
return s
}

func TestSlogtest(t *testing.T) {
var buf bytes.Buffer
newHandler := func(*testing.T) slog.Handler {
buf.Reset()
return log.NewHandler(&buf, &log.Options{Level: slog.LevelDebug})
}

results := func(*testing.T) map[string]any {
for _, line := range strings.Split(buf.String(), "\n") {
if len(line) == 0 {
continue
}
m, err := parseLogLine(line)
if err != nil {
t.Fatalf("Failed to parse log line: %v", err)
}
return m
}
return nil
}

slogtest.Run(t, newHandler, results)
}
// TODO: slogtest.Run was added in Go 1.22. Waiting for https://github.com/aquasecurity/trivy/pull/6075.
//func TestSlogtest(t *testing.T) {
// var buf bytes.Buffer
// newHandler := func(*testing.T) slog.Handler {
// buf.Reset()
// return log.NewHandler(&buf, &log.Options{Level: slog.LevelDebug})
// }
//
// results := func(*testing.T) map[string]any {
// for _, line := range strings.Split(buf.String(), "\n") {
// if len(line) == 0 {
// continue
// }
// m, err := parseLogLine(line)
// if err != nil {
// t.Fatalf("Failed to parse log line: %v", err)
// }
// return m
// }
// return nil
// }
//
// slogtest.Run(t, newHandler, results)
//}

func parseLogLine(line string) (map[string]any, error) {
parts := strings.SplitN(line, "\t", 4)
Expand Down

0 comments on commit a6288d5

Please sign in to comment.