mirror of
https://github.com/mulgadc/spinifex.git
synced 2026-10-19 10:52:04 +00:00
40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
//go:build e2e
|
|
|
|
package harness
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/mulgadc/spinifex/spinifex/utils"
|
|
)
|
|
|
|
// KVReplicaFactors connects to the cluster NATS and returns the configured
|
|
// replica factor for each named KV bucket, read from JetStream stream metadata
|
|
// (the "KV_" stream prefix is applied internally). The replica count lives in
|
|
// cluster-global Raft metadata, so any node's NATS reports the same value.
|
|
// Fatals if NATS is unreachable or a bucket's stream cannot be introspected.
|
|
func KVReplicaFactors(t *testing.T, env *Env, buckets ...string) map[string]int {
|
|
t.Helper()
|
|
host, token, ca := natsConn(t, env)
|
|
nc, err := utils.ConnectNATS(host, token, ca)
|
|
if err != nil {
|
|
t.Fatalf("connect NATS %s: %v", host, err)
|
|
}
|
|
defer nc.Close()
|
|
|
|
js, err := nc.JetStream()
|
|
if err != nil {
|
|
t.Fatalf("jetstream context: %v", err)
|
|
}
|
|
|
|
out := make(map[string]int, len(buckets))
|
|
for _, b := range buckets {
|
|
info, err := js.StreamInfo("KV_" + b)
|
|
if err != nil {
|
|
t.Fatalf("stream info for KV bucket %q: %v", b, err)
|
|
}
|
|
out[b] = info.Config.Replicas
|
|
}
|
|
return out
|
|
}
|