39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package redisproxy
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"linkport/internal/model"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestResponseTimingPreservesPipelinePushAndUnknownRESP(t *testing.T) {
|
|
for _, wire := range []string{"+OK\r\n>2\r\n+notice\r\n+data\r\n$5\r\nvalue\r\n", "|1\r\n+k\r\n+v\r\n+OK\r\n*2\r\n:1\r\n$-1\r\n", "$?\r\n;3\r\nabc\r\n;0\r\n"} {
|
|
var got []model.Execution
|
|
ctx := model.WithExecutionObserver(context.Background(), func(e model.Execution) { got = append(got, e) })
|
|
var q model.ExecutionQueue
|
|
q.Start("first")
|
|
q.Start("second")
|
|
var out bytes.Buffer
|
|
relayReplies(ctx, &out, strings.NewReader(wire), &q)
|
|
if out.String() != wire {
|
|
t.Fatalf("response altered: %q", out.String())
|
|
}
|
|
want := 2
|
|
if strings.HasPrefix(wire, "$?") {
|
|
want = 0
|
|
}
|
|
if len(got) != want {
|
|
t.Fatalf("wrong correlation: %+v", got)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestRedisPressureMetricsDoNotExposeINFOSecrets(t *testing.T) {
|
|
got := redisMetrics("connected_clients:7\r\nused_memory:1024\r\nmaster_auth:private\r\nused_cpu_sys:2.5\r\n")
|
|
if len(got) != 3 || got[0].Value != 7 || got[2].Value != 2.5 {
|
|
t.Fatalf("metrics: %+v", got)
|
|
}
|
|
}
|