* H-300: wire Captain Skills into Web runtime * H-300: enforce effective model and conservative skill budget * H-300: fix CI gosec step * ci: extend golangci-lint timeout * fix lint findings across backend * fix(push): resolve delivery protocol blockers * test(repository): close SQLite test databases * test(repository): reuse SQLite schema per package * H-307: restore backend Go cache in CI * H-307: prefetch modules before cold lint * H-307: resolve govulncheck security gate * H-307: build lint with patched Go toolchain * H-307: clear remaining security scan findings --------- Co-authored-by: Rogee <rogee@ipao.vip>
94 lines
2.2 KiB
Go
94 lines
2.2 KiB
Go
package pubsub
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/ThreeDotsLabs/watermill"
|
|
"github.com/alicebob/miniredis/v2"
|
|
"github.com/redis/go-redis/v9"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestZapLoggerAdapter_All_Cov2(t *testing.T) {
|
|
l := &zapLoggerAdapter{}
|
|
l.Error("test", nil, nil)
|
|
l.Error("test", context.Canceled, nil)
|
|
l.Info("test", nil)
|
|
l.Debug("test", nil)
|
|
l.Trace("test", nil)
|
|
result := l.With(nil)
|
|
require.NotNil(t, result)
|
|
}
|
|
|
|
func TestRedisPubSub_WithMiniredis_Cov2(t *testing.T) {
|
|
mr := miniredis.RunT(t)
|
|
client := redis.NewClient(&redis.Options{Addr: mr.Addr()})
|
|
defer client.Close()
|
|
|
|
ps, err := NewRedisPubSub(client)
|
|
require.NoError(t, err)
|
|
require.NotNil(t, ps)
|
|
defer ps.Close()
|
|
|
|
// Test Publish
|
|
_ = ps.Publish(context.Background(), "test-topic", Event{Type: "test", AccountID: 1})
|
|
|
|
// Test Subscribe
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
_ = ps.Subscribe(ctx, "test-topic", func(event Event) {})
|
|
|
|
// Test Unsubscribe
|
|
require.NoError(t, ps.Unsubscribe(ctx, "test-topic"))
|
|
}
|
|
|
|
func TestRedisPubSub_NilClient_Cov2(t *testing.T) {
|
|
_, err := NewRedisPubSub(nil)
|
|
require.Error(t, err)
|
|
}
|
|
|
|
func TestNewEventBus_WithMiniredis_Cov2(t *testing.T) {
|
|
mr := miniredis.RunT(t)
|
|
client := redis.NewClient(&redis.Options{Addr: mr.Addr()})
|
|
defer client.Close()
|
|
|
|
bus, err := NewEventBus(client)
|
|
_ = err
|
|
_ = bus
|
|
if bus != nil {
|
|
_ = bus.Close()
|
|
}
|
|
}
|
|
|
|
func TestEventBus_Publish_WithMiniredis_Cov2(t *testing.T) {
|
|
mr := miniredis.RunT(t)
|
|
client := redis.NewClient(&redis.Options{Addr: mr.Addr()})
|
|
defer client.Close()
|
|
|
|
bus, err := NewEventBus(client)
|
|
if err != nil || bus == nil {
|
|
t.Skip("could not create event bus")
|
|
}
|
|
defer bus.Close()
|
|
|
|
defer func() { _ = recover() }()
|
|
_ = bus.Publish("test-topic", []byte(`{"key":"value"}`))
|
|
}
|
|
|
|
func TestNewSubscriber_WithMiniredis_Cov2(t *testing.T) {
|
|
mr := miniredis.RunT(t)
|
|
client := redis.NewClient(&redis.Options{Addr: mr.Addr()})
|
|
defer client.Close()
|
|
|
|
defer func() { _ = recover() }()
|
|
_, _ = NewSubscriber(client, "test-consumer")
|
|
}
|
|
|
|
func TestFormatTopic_All_Cov2(t *testing.T) {
|
|
require.Equal(t, "gochat:test", FormatTopic("gochat:%s", "test"))
|
|
require.Contains(t, FormatTopic("account:%s", "123"), "account:123")
|
|
}
|
|
|
|
var _ = watermill.LogFields{}
|