//go:build integration package broker import ( "testing" "github.com/nats-io/nats.go" ) func TestABucketIsAssertedInPlace(t *testing.T) { js := aLiveBus(t) b := Bucket{Module: "statetest", Name: "servers"} if _, err := RaiseBuckets(js, []Bucket{b}); err != nil { t.Fatalf("a real server refused a module's bucket: %v", err) } kv, err := js.Context().KeyValue(b.Bucket()) if err != nil { t.Fatal(err) } if _, err := kv.Put("all.one", []byte(`{"kept":true}`)); err != nil { t.Fatal(err) } b.History = 3 if _, err := RaiseBuckets(js, []Bucket{b}); err != nil { t.Fatalf("asserting the bucket again failed, so a restart would: %v", err) } got, err := kv.Get("all.one") if err != nil || string(got.Value()) != `{"kept":true}` { t.Fatalf("asserting again lost what the bucket held: %v %v", got, err) } status, err := kv.Status() if err != nil { t.Fatal(err) } if status.History() != 3 { t.Fatalf("history is %d, the owner declared 3", status.History()) } if s, ok := status.(*nats.KeyValueBucketStatus); ok { if c := s.StreamInfo().Config; c.MaxMsgSize != StateMaxValueBytes || c.MaxBytes != StateMaxBytes { t.Fatalf("the mesh's caps are not on the bucket: value %d, bucket %d", c.MaxMsgSize, c.MaxBytes) } } } func TestABucketIsAssertedOverAHeldConnection(t *testing.T) { js := aLiveBus(t) held := OnConn(js.Conn()) if _, err := RaiseBuckets(held, []Bucket{{Module: "statetest", Name: "held"}}); err != nil { t.Fatalf("asserting over a held connection failed: %v", err) } if _, err := js.Context().KeyValue("statetest_held"); err != nil { t.Fatalf("the bucket is not there: %v", err) } }