- 补入库:server/internal/db/dump.go、redis 分页/扫描预算测试、opsxdb-mcp main_test、 packages/opsxdb-mcp package-lock、docs 审计与对比文档等 37 个新文件 - 含结构扁平化进行中的 80 处修改与 155 处旧结构删除(server/ src/ src-tauri/ 为当前有效源) - 构建产物(bin/target/dist)与签名私钥仍按规则排除
43 lines
1.3 KiB
Go
43 lines
1.3 KiB
Go
package db
|
|
|
|
import (
|
|
"context"
|
|
"github.com/redis/go-redis/v9"
|
|
"testing"
|
|
)
|
|
|
|
type budgetRedis struct {
|
|
redis.UniversalClient
|
|
calls int
|
|
batch []string
|
|
}
|
|
|
|
func (c *budgetRedis) Scan(ctx context.Context, cursor uint64, match string, count int64) *redis.ScanCmd {
|
|
c.calls++
|
|
cmd := redis.NewScanCmd(ctx, nil, "scan")
|
|
cmd.SetVal(c.batch, uint64(c.calls))
|
|
return cmd
|
|
}
|
|
func TestRedisScanBudgetSparseMatches(t *testing.T) {
|
|
c := &budgetRedis{}
|
|
names, truncated, err := scanAll(context.Background(), c, "missing*", 200, 500, 20)
|
|
if err != nil || !truncated || len(names) != 0 || c.calls != 20 {
|
|
t.Fatalf("calls=%d names=%v truncated=%v err=%v", c.calls, names, truncated, err)
|
|
}
|
|
}
|
|
func TestRedisScanCountIsNotHardLimit(t *testing.T) {
|
|
c := &budgetRedis{batch: []string{"a", "b", "c"}}
|
|
names, truncated, err := scanAll(context.Background(), c, "*", 1, 2, 20)
|
|
if err != nil || !truncated || len(names) != 2 || c.calls != 1 {
|
|
t.Fatalf("names=%v calls=%d truncated=%v err=%v", names, c.calls, truncated, err)
|
|
}
|
|
}
|
|
|
|
func TestRedisBrowsePattern(t *testing.T) {
|
|
for input, want := range map[string]string{"order": "*order*", "order:*": "order:*", "*": "*"} {
|
|
if got := redisBrowsePattern(input); got != want {
|
|
t.Fatalf("input=%q got=%q want=%q", input, got, want)
|
|
}
|
|
}
|
|
}
|