mirror of
https://github.com/redis/go-redis.git
synced 2026-10-28 08:24:54 +08:00
* feat(csc): metadata-driven command eligibility * fix linting issues * feat(csc): add dynamic metadata resolver * fix incompatibillity issues * fix issues * fix issues * fix issues * feat(csc): share dynamic command metadata * correct cluster metadata and routing * Reuse identicle records without building it from scratch again * Address comments * Address comments * Address comments * Address ci failures * harden metadata and cluster routing * verify metadata and list all nodes * fix hello callback * Perf improvements * fix bless scan routing methods * refactor(csc): separate cluster routing * Add server identification in HELLO && Split csc checks in autopipline
33 lines
984 B
Go
33 lines
984 B
Go
package redis
|
|
|
|
import (
|
|
"context"
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
// A negative constructor hint must not cause an invalid argument access.
|
|
// Resolved metadata remains authoritative over the public key-position hint.
|
|
func TestCSCNegativeKeyPositionHint(t *testing.T) {
|
|
ctx := context.Background()
|
|
get := NewStringCmd(ctx, "get", "k")
|
|
get.SetFirstKeyPos(-1)
|
|
mget := NewSliceCmd(ctx, "mget", "a", "b")
|
|
mget.SetFirstKeyPos(-3)
|
|
for _, cmd := range []Cmder{get, mget} {
|
|
meta, ok := cscCommandMetaFor(cmd)
|
|
if !ok || !cscCanExtractRedisKeys(meta, cmd) {
|
|
t.Fatalf("%s: constructor hint overrode valid metadata", cmd.Name())
|
|
}
|
|
keys := extractRedisKeys(cmd)
|
|
cmd.SetFirstKeyPos(1)
|
|
if want := extractRedisKeys(cmd); !reflect.DeepEqual(keys, want) {
|
|
t.Errorf("%s: keys = %v, want %v", cmd.Name(), keys, want)
|
|
}
|
|
meta.firstKey = -1
|
|
if cscCanExtractRedisKeys(meta, cmd) || keyArgOK(cmd, -1) {
|
|
t.Errorf("%s: accepted a negative metadata key position", cmd.Name())
|
|
}
|
|
}
|
|
}
|