feat(store/valkey): Add Redis(R) Sentinel support (#1294)
* feat(internal): add ListOr[T any] type This is a utility type that lets you decode a JSON T or list of T as a single value. This will be used with Redis Sentinel config so that you can specify multiple sentinel addresses. Ref TecharoHQ/botstopper#24 Assisted-by: GLM 4.6 via Claude Code Signed-off-by: Xe Iaso <me@xeiaso.net> * feat(store/valkey): add Redis(R) Sentinel support Signed-off-by: Xe Iaso <me@xeiaso.net> * chore: spelling check-spelling run (pull_request) for Xe/redis-sentinel Signed-off-by: check-spelling-bot <check-spelling-bot@users.noreply.github.com> on-behalf-of: @check-spelling <check-spelling-bot@check-spelling.dev> * chore(store/valkey): remove pointless comments Signed-off-by: Xe Iaso <me@xeiaso.net> * docs: document the Redis™ Sentinel configuration options Signed-off-by: Xe Iaso <me@xeiaso.net> * fix(store/valkey): Redis™ Sentinel doesn't require a password Signed-off-by: Xe Iaso <me@xeiaso.net> * chore: spelling Signed-off-by: Xe Iaso <me@xeiaso.net> * chore: spelling Signed-off-by: Xe Iaso <me@xeiaso.net> --------- Signed-off-by: Xe Iaso <me@xeiaso.net> Signed-off-by: check-spelling-bot <check-spelling-bot@users.noreply.github.com>
This commit is contained in:
parent
69e9023cbb
commit
02989f03d0
7 changed files with 321 additions and 24 deletions
|
|
@ -2,6 +2,7 @@ package valkey
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
|
|
@ -45,3 +46,86 @@ func TestImpl(t *testing.T) {
|
|||
|
||||
storetest.Common(t, Factory{}, json.RawMessage(data))
|
||||
}
|
||||
|
||||
func TestFactoryValid(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
jsonData string
|
||||
expectError error
|
||||
}{
|
||||
{
|
||||
name: "empty config",
|
||||
jsonData: `{}`,
|
||||
expectError: ErrNoURL,
|
||||
},
|
||||
{
|
||||
name: "valid URL only",
|
||||
jsonData: `{"url": "redis://localhost:6379"}`,
|
||||
expectError: nil,
|
||||
},
|
||||
{
|
||||
name: "invalid URL",
|
||||
jsonData: `{"url": "invalid-url"}`,
|
||||
expectError: ErrBadURL,
|
||||
},
|
||||
{
|
||||
name: "valid sentinel config",
|
||||
jsonData: `{"sentinel": {"masterName": "mymaster", "addr": ["localhost:26379"], "password": "mypass"}}`,
|
||||
expectError: nil,
|
||||
},
|
||||
{
|
||||
name: "sentinel missing masterName",
|
||||
jsonData: `{"sentinel": {"addr": ["localhost:26379"], "password": "mypass"}}`,
|
||||
expectError: ErrSentinelMasterNameRequired,
|
||||
},
|
||||
{
|
||||
name: "sentinel missing addr",
|
||||
jsonData: `{"sentinel": {"masterName": "mymaster", "password": "mypass"}}`,
|
||||
expectError: ErrSentinelAddrRequired,
|
||||
},
|
||||
{
|
||||
name: "sentinel empty addr",
|
||||
jsonData: `{"sentinel": {"masterName": "mymaster", "addr": [""], "password": "mypass"}}`,
|
||||
expectError: ErrSentinelAddrEmpty,
|
||||
},
|
||||
{
|
||||
name: "sentinel missing password",
|
||||
jsonData: `{"sentinel": {"masterName": "mymaster", "addr": ["localhost:26379"]}}`,
|
||||
expectError: nil,
|
||||
},
|
||||
{
|
||||
name: "sentinel with optional fields",
|
||||
jsonData: `{"sentinel": {"masterName": "mymaster", "addr": ["localhost:26379"], "password": "mypass", "clientName": "myclient", "username": "myuser"}}`,
|
||||
expectError: nil,
|
||||
},
|
||||
{
|
||||
name: "sentinel single address (not array)",
|
||||
jsonData: `{"sentinel": {"masterName": "mymaster", "addr": "localhost:26379", "password": "mypass"}}`,
|
||||
expectError: nil,
|
||||
},
|
||||
{
|
||||
name: "sentinel mixed empty and valid addresses",
|
||||
jsonData: `{"sentinel": {"masterName": "mymaster", "addr": ["", "localhost:26379", ""], "password": "mypass"}}`,
|
||||
expectError: nil,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
factory := Factory{}
|
||||
err := factory.Valid(json.RawMessage(tt.jsonData))
|
||||
|
||||
if tt.expectError == nil {
|
||||
if err != nil {
|
||||
t.Errorf("expected no error, got: %v", err)
|
||||
}
|
||||
} else {
|
||||
if err == nil {
|
||||
t.Errorf("expected error %v, got nil", tt.expectError)
|
||||
} else if !errors.Is(err, tt.expectError) {
|
||||
t.Errorf("expected error %v, got: %v", tt.expectError, err)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue