Files
mesh-delivery/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/seatlist_test.go
T
jschoubben db3f07d277 A-278: the assigner, builder, indexer and pipeline runner pass seatlist.Definition to AnswerSeat
Their four copies of the seat-definition function go; each passes its seat list part's reader to mesh-sdk's one.

Builds: design 47 G A-278, A-186

Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
2026-11-12 11:39:57 +01:00

51 lines
1.8 KiB
Go

package main
import (
"encoding/json"
"errors"
"testing"
"time"
"git.novox.be/novox/mesh-sdk/go/busretry"
"git.novox.be/novox/mesh-sdk/go/seatlist"
)
// listingCatalog is the seat mesh-catalog as the reader asks it: an empty listing, so the bootstrapped definitions stand, or,
// silent, no answer at all.
type listingCatalog struct{ silent bool }
func (c listingCatalog) Ask(string, any) (json.RawMessage, error) {
if c.silent {
return nil, errors.New("no responders")
}
return json.Marshal(seatlist.Listing{Revision: 1})
}
func (listingCatalog) Subscribe(string, func(string, json.RawMessage) error) error { return nil }
// A-179, A-186: the definition the verb reserved's callers are checked against is the seat list's, none before the reader
// starts or while the seat mesh-catalog has not answered, and none for a seat the list does not hold.
func TestTheAnsweredSeatsDefinitionIsTheSeatListsOnceRead(t *testing.T) {
t.Cleanup(busretry.Waits(20*time.Millisecond, time.Millisecond, 5*time.Millisecond))
follow := func(silent bool) *seatGate {
g := newSeatGate()
if r := g.Follow(listingCatalog{silent: silent}, nil, t.Logf); r != nil {
<-r.Ready()
}
return g
}
if _, ok := seatlist.Definition(newSeatGate().Reader, seatlist.Seat)(); ok {
t.Error("a definition is answered before the seat list's reader started")
}
if _, ok := seatlist.Definition(follow(true).Reader, seatlist.Seat)(); ok {
t.Error("a definition is answered while the seat mesh-catalog has not answered the list")
}
read := follow(false)
if d, ok := seatlist.Definition(read.Reader, seatlist.Seat)(); !ok || d.Seat != seatlist.Seat {
t.Errorf("the read list's %s is answered as %q, %v", seatlist.Seat, d.Seat, ok)
}
if _, ok := seatlist.Definition(read.Reader, "no-such-seat")(); ok {
t.Error("a seat the list does not hold is answered a definition")
}
}