Valkey (Redis-compatible) client component with launcher lifecycle and health check integration. What's included: - Config with Addrs, Password, SelectDB, CacheSizeEachConn (env-driven) - Provider interface exposing native valkey-go Client() directly (no wrapper) - Component interface: launcher.Component + health.Checkable + Provider - New(logger, cfg) constructor for lifecycle registration via lc.Append - Health check via PING at LevelDegraded priority - Graceful shutdown calling client.Close() in OnStop Tested-via: todo-api POC integration Reviewed-against: docs/adr/
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package valkey
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"code.nochebuena.dev/go/health"
|
|
"code.nochebuena.dev/go/logz"
|
|
)
|
|
|
|
func newLogger() logz.Logger { return logz.New(logz.Options{}) }
|
|
|
|
func TestNew(t *testing.T) {
|
|
if New(newLogger(), Config{}) == nil {
|
|
t.Fatal("New returned nil")
|
|
}
|
|
}
|
|
|
|
func TestComponent_Name(t *testing.T) {
|
|
c := New(newLogger(), Config{}).(health.Checkable)
|
|
if c.Name() != "valkey" {
|
|
t.Errorf("want valkey, got %s", c.Name())
|
|
}
|
|
}
|
|
|
|
func TestComponent_Priority(t *testing.T) {
|
|
c := New(newLogger(), Config{}).(health.Checkable)
|
|
if c.Priority() != health.LevelDegraded {
|
|
t.Error("Priority() != LevelDegraded")
|
|
}
|
|
}
|
|
|
|
func TestComponent_OnStop_NilClient(t *testing.T) {
|
|
c := &vkComponent{logger: newLogger()}
|
|
if err := c.OnStop(); err != nil {
|
|
t.Errorf("OnStop with nil client: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestComponent_OnInit_InvalidAddr(t *testing.T) {
|
|
// An empty Addrs slice should cause NewClient to fail or produce an error.
|
|
c := New(newLogger(), Config{Addrs: []string{}})
|
|
err := c.OnInit()
|
|
// valkey-go may not error on empty addr until first command;
|
|
// just verify it doesn't panic and returns a component.
|
|
_ = err
|
|
}
|