fix: redis's pipeline logs are not printed completely (#2538)

* fix: redis's pipeline logs are not printed completely

* add unit test

Signed-off-by: liaoshiwei <liaoshiwei@uniontech.com>

Signed-off-by: liaoshiwei <liaoshiwei@uniontech.com>
This commit is contained in:
swliao425
2022-10-22 21:57:40 +08:00
committed by GitHub
parent 7c9ef3ca67
commit b21162d638
2 changed files with 25 additions and 7 deletions

View File

@@ -163,6 +163,17 @@ func TestHookProcessPipelineCase5(t *testing.T) {
assert.True(t, buf.Len() == 0)
}
func TestLogDuration(t *testing.T) {
w, restore := injectLog()
defer restore()
logDuration(context.Background(), []red.Cmder{red.NewCmd(context.Background(), "get", "foo")}, 1*time.Second)
assert.True(t, strings.Contains(w.String(), "get foo"))
logDuration(context.Background(), []red.Cmder{red.NewCmd(context.Background(), "get", "foo"), red.NewCmd(context.Background(), "set", "bar", 0)}, 1*time.Second)
assert.True(t, strings.Contains(w.String(), "get foo\\nset bar 0"))
}
func injectLog() (r *strings.Builder, restore func()) {
var buf strings.Builder
w := logx.NewWriter(&buf)