Skip to content

Commit b2228f4

Browse files
committed
fix tests
1 parent 6031458 commit b2228f4

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

main_test.go

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package redis_test
33
import (
44
"context"
55
"fmt"
6+
"log"
67
"net"
78
"os"
89
"strconv"
@@ -14,7 +15,6 @@ import (
1415
. "github.com/bsm/ginkgo/v2"
1516
. "github.com/bsm/gomega"
1617
"github.com/redis/go-redis/v9"
17-
"github.com/redis/go-redis/v9/internal"
1818
)
1919

2020
const (
@@ -55,6 +55,8 @@ var (
5555
sentinel1, sentinel2, sentinel3 *redis.Client
5656
)
5757

58+
var TLogger *TestLogger
59+
5860
var cluster = &clusterScenario{
5961
ports: []string{"16600", "16601", "16602", "16603", "16604", "16605"},
6062
nodeIDs: make([]string, 6),
@@ -106,9 +108,10 @@ var _ = BeforeSuite(func() {
106108
fmt.Printf("CLIENT_LIBS_TEST_IMAGE: %v\n", os.Getenv("CLIENT_LIBS_TEST_IMAGE"))
107109

108110
// set logger that will filter some of the noise from the tests
109-
tlogger := NewTestLogger()
110-
tlogger.Filter("ERR unknown subcommand 'maint_notifications'")
111-
redis.SetLogger(tlogger)
111+
TLogger := NewTestLogger()
112+
TLogger.Filter("ERR unknown subcommand 'maint_notifications'")
113+
TLogger.Filter("test panic")
114+
redis.SetLogger(TLogger)
112115

113116
if RedisVersion < 7.0 || RedisVersion > 9 {
114117
panic("incorrect or not supported redis version")
@@ -408,8 +411,7 @@ func (h *hook) ProcessPipelineHook(hook redis.ProcessPipelineHook) redis.Process
408411
}
409412

410413
func NewTestLogger() *TestLogger {
411-
intLogger := internal.Logger
412-
414+
intLogger := log.New(os.Stderr, "redis: ", log.LstdFlags|log.Lshortfile)
413415
return &TestLogger{
414416
intLogger,
415417
[]string{},
@@ -419,18 +421,31 @@ func NewTestLogger() *TestLogger {
419421
// TestLogger is a logger that filters out specific substrings so
420422
// the test output is not polluted with noise.
421423
type TestLogger struct {
422-
intLogger internal.Logging
423-
filteredSugstrings []string
424+
log *log.Logger
425+
filteredSubstrings []string
426+
}
427+
428+
// Filter adds a substring to the filter list.
429+
func (tl *TestLogger) Filter(substr string) {
430+
tl.filteredSubstrings = append(tl.filteredSubstrings, substr)
424431
}
425432

426-
func (t *TestLogger) Filter(substr string) {
427-
t.filteredSugstrings = append(t.filteredSugstrings, substr)
433+
// Unfilter removes a substring from the filter list.
434+
func (tl *TestLogger) Unfilter(substr string) {
435+
for i, s := range tl.filteredSubstrings {
436+
if s == substr {
437+
tl.filteredSubstrings = append(tl.filteredSubstrings[:i], tl.filteredSubstrings[i+1:]...)
438+
return
439+
}
440+
}
428441
}
429-
func (t *TestLogger) Printf(_ context.Context, format string, v ...interface{}) {
430-
for _, substr := range t.filteredSugstrings {
431-
if strings.Contains(format, substr) {
442+
443+
func (tl *TestLogger) Printf(_ context.Context, format string, v ...interface{}) {
444+
msg := fmt.Sprintf(format, v...)
445+
for _, substr := range tl.filteredSubstrings {
446+
if strings.Contains(msg, substr) {
432447
return
433448
}
434449
}
435-
t.intLogger.Printf(ctx, format, v...)
450+
_ = tl.log.Output(2, msg)
436451
}

0 commit comments

Comments
 (0)