nitter/internal/logging/test_logger.go
Peter Kurfer eee9a30503
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
test(gitea): test approval behavior
2023-03-10 10:25:07 +01:00

29 lines
452 B
Go

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
}