nitter/internal/logging/test_logger.go

30 lines
452 B
Go
Raw Normal View History

2023-03-10 09:19:41 +00:00
package logging
import (
"io"
"testing"
"golang.org/x/exp/slog"
)
var _ io.Writer = (*testWriter)(nil)
func NewWriter(tb testing.TB) io.Writer {
tb.Helper()
return testWriter{tb: tb}
}
func NewLogger(tb testing.TB) *slog.Logger {
tb.Helper()
return slog.New(slog.NewTextHandler(NewWriter(tb)))
}
type testWriter struct {
tb testing.TB
}
func (t testWriter) Write(p []byte) (n int, err error) {
t.tb.Log(string(p))
return len(p), nil
}