52 lines
1.4 KiB
Go
52 lines
1.4 KiB
Go
package valkey_test
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"messenger/internal/platform/valkey"
|
|
"messenger/internal/testenv"
|
|
)
|
|
|
|
func TestNewClientPingsAndBoundsWaiting(t *testing.T) {
|
|
ctx := context.Background()
|
|
kv, err := testenv.StartValkey(ctx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer kv.Close()
|
|
|
|
client, err := valkey.NewClient(ctx, kv.URL)
|
|
if err != nil {
|
|
t.Fatalf("NewClient: %v", err)
|
|
}
|
|
defer client.Close()
|
|
opts := client.Options()
|
|
if opts.DialTimeout != 2*time.Second || opts.ReadTimeout != time.Second || opts.WriteTimeout != time.Second {
|
|
t.Fatalf("timeouts = %v/%v/%v, want 2s/1s/1s", opts.DialTimeout, opts.ReadTimeout, opts.WriteTimeout)
|
|
}
|
|
// go-redis stores the requested -1 ("no retries") as 0 after init; its
|
|
// default would be 3.
|
|
if opts.PoolSize != 10 || opts.MaxRetries != 0 {
|
|
t.Fatalf("PoolSize = %d, MaxRetries = %d; want 10 and 0 (fail fast)", opts.PoolSize, opts.MaxRetries)
|
|
}
|
|
}
|
|
|
|
func TestNewClientErrorsNeverEchoTheURL(t *testing.T) {
|
|
ctx := context.Background()
|
|
for name, url := range map[string]string{
|
|
"malformed": "redis://:s3cret@host:port/x",
|
|
"unreachable": "redis://:s3cret@127.0.0.1:1/0",
|
|
} {
|
|
_, err := valkey.NewClient(ctx, url)
|
|
if err == nil {
|
|
t.Fatalf("%s: want error", name)
|
|
}
|
|
if strings.Contains(err.Error(), "s3cret") {
|
|
t.Fatalf("%s: error leaks the password: %v", name, err)
|
|
}
|
|
}
|
|
}
|