Files
mesh-delivery/modules/mesh-grants/internal/grants/statecap_test.go
T
2026-11-12 11:00:33 +01:00

41 lines
1.3 KiB
Go

package grants
import (
"testing"
"git.novox.be/novox/mesh-sdk/go/catalogue"
)
// raiser is a Creator that holds one stream at a cap and records the cap it is raised to.
type raiser struct {
Creator
to int64
}
func (r *raiser) RaiseMaxBytes(_ string, to int64) (int64, bool, error) {
r.to = to
return 64 << 20, true, nil
}
// A state's declared max-mib reaches the bucket (issue 1975 note 6): the composed stream carries it, and a bucket the bus
// holds at the default 64 MiB is raised to it by the assertion.
func TestAStatesDeclaredCapReachesItsBucket(t *testing.T) {
m := catalogue.Manifest{Module: "mesh-delivery-checker", State: []catalogue.StateDeclaration{{Name: "compositions", MaxMiB: 256}}}
var composed *Item
for _, it := range Composed(m, nil) {
if it.Stream == "KV_mesh-delivery-checker_compositions" {
composed = &it
}
}
if composed == nil || composed.Composed.MaxBytes != 256<<20 {
t.Fatalf("the composed bucket is %+v, want a cap of 256 MiB", composed)
}
a := Assertion{Manifest: "d", Items: []Item{*composed}}
a.Items[0].Held = &Limits{MaxBytes: 64 << 20}
r := &raiser{}
_, raises := createMissing(r, &creations{}, &a, m, nil, false)
if r.to != 256<<20 || len(raises) != 1 {
t.Errorf("the held bucket was raised to %d (%v), want 256 MiB", r.to, raises)
}
}