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
|
||
|
|
}
|