mirror of
https://github.com/acaloiaro/neoq
synced 2026-07-21 02:09:47 +00:00
maint: clean up testutils/TestLogger
This commit is contained in:
parent
bc8df98894
commit
2ce00761c7
5 changed files with 18 additions and 11 deletions
|
|
@ -35,6 +35,9 @@ changelog:
|
|||
- title: Features
|
||||
regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$'
|
||||
order: 0
|
||||
- title: Maintenance
|
||||
regexp: '^.*?maint(\([[:word:]]+\))??!?:.+$'
|
||||
order: 1
|
||||
- title: "Bug fixes"
|
||||
regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$'
|
||||
- title: Others
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
|
@ -324,7 +323,7 @@ func TestBasicJobProcessingWithErrors(t *testing.T) {
|
|||
return
|
||||
})
|
||||
|
||||
nq.SetLogger(testutils.TestLogger{L: log.New(testutils.ChanWriter{Ch: logsChan}, "", 0)})
|
||||
nq.SetLogger(testutils.NewTestLogger(logsChan))
|
||||
|
||||
err = nq.Start(ctx, queue, h)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -266,8 +266,7 @@ func TestJobProcessingWithOptions(t *testing.T) {
|
|||
}
|
||||
defer nq.Shutdown(ctx)
|
||||
|
||||
logger := testutils.TestLogger{L: log.New(&testutils.ChanWriter{Ch: logsChan}, "", 0)}
|
||||
nq.SetLogger(logger)
|
||||
nq.SetLogger(testutils.NewTestLogger(logsChan))
|
||||
|
||||
h := handler.New(func(_ context.Context) (err error) {
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
|
@ -206,7 +205,7 @@ func TestSetLogger(t *testing.T) {
|
|||
}
|
||||
defer nq.Shutdown(ctx)
|
||||
|
||||
nq.SetLogger(testutils.TestLogger{L: log.New(testutils.ChanWriter{Ch: logsChan}, "", 0)})
|
||||
nq.SetLogger(testutils.NewTestLogger(logsChan))
|
||||
|
||||
h := handler.New(func(ctx context.Context) (err error) {
|
||||
err = errTrigger
|
||||
|
|
|
|||
|
|
@ -7,31 +7,38 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
// NewTestLogger returns a new TestLogger that logs messages to the given channel
|
||||
func NewTestLogger(ch chan string) *TestLogger {
|
||||
return &TestLogger{
|
||||
L: log.New(ChanWriter{ch: ch}, "", 0),
|
||||
}
|
||||
}
|
||||
|
||||
// TestLogger is a utility for logging in tests
|
||||
type TestLogger struct {
|
||||
L *log.Logger
|
||||
}
|
||||
|
||||
// Info prints to stdout and signals its done channel
|
||||
// Info prints to stdout, with args separated by spaces
|
||||
func (h TestLogger) Info(m string, args ...any) {
|
||||
h.L.Println(m, args)
|
||||
}
|
||||
|
||||
// Debug prints to stdout and signals its done channel
|
||||
// Debug prints to stdout, with args separates by spaces
|
||||
func (h TestLogger) Debug(m string, args ...any) {
|
||||
h.L.Println(m, args)
|
||||
}
|
||||
|
||||
// Error prints to stdout and signals its done channel
|
||||
// Error prints to stdout with args separated by spaces
|
||||
func (h TestLogger) Error(m string, args ...any) {
|
||||
h.L.Println(m, args)
|
||||
}
|
||||
|
||||
type ChanWriter struct {
|
||||
Ch chan string
|
||||
ch chan string
|
||||
}
|
||||
|
||||
func (c ChanWriter) Write(p []byte) (n int, err error) {
|
||||
c.Ch <- strings.Trim(string(p), "\n")
|
||||
c.ch <- strings.Trim(string(p), "\n")
|
||||
return len(p), nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue