35 lines
994 B
Go
35 lines
994 B
Go
package protocollog
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/alicebob/miniredis/v2"
|
|
"github.com/redis/go-redis/v9"
|
|
)
|
|
|
|
func TestNewUsesLocalRedisWhenURLIsEmpty(t *testing.T) {
|
|
publisher, err := New("")
|
|
if err != nil {
|
|
t.Fatalf("New returned error: %v", err)
|
|
}
|
|
if publisher == nil || publisher.Redis == nil {
|
|
t.Fatal("expected an initialized Redis client")
|
|
}
|
|
if got := publisher.Redis.Options().Addr; got != "127.0.0.1:6379" {
|
|
t.Fatalf("expected local Redis fallback, got %q", got)
|
|
}
|
|
}
|
|
|
|
func TestFailuresAreNeverSampledOut(t *testing.T) {
|
|
mr := miniredis.RunT(t)
|
|
client := redis.NewClient(&redis.Options{Addr: mr.Addr()})
|
|
p := &Publisher{Redis: client, SuccessSampleRate: 1, MaxLen: 100}
|
|
if err := p.Publish(context.Background(), Event{Protocol: "cmpp", EventType: "submit", Status: "failed", ResultCode: "TIMEOUT"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if client.XLen(context.Background(), p.StreamName()).Val() != 1 {
|
|
t.Fatal("failed protocol event must be retained")
|
|
}
|
|
}
|