Files
mesh-sdk/go/seatlist/holder_test.go
T
jschoubben 5fa64be894 Revert the revert of G's mesh-sdk merge (#191): G's sdk stands again over reader release 3
Main reverted G's half merge (#189, reverted by 8afc3eb in #191) and then took the reader release's S1-S5, which
copied G's code. G's form holds where they differ (process_bus.go, seats.go, state.go and their tests); the
release's kept names stay so main's callers keep building: SeatViewPrefix beside SeatReadPrefix, and QueueInvoke's
empty strings on not-ok (with its test TestQueueInvoke). The tree differs from G's head f30dee54 only by those and
the release's two tests (objects cap option, seat states and stream kinds).

Builds: design 47 G (the milestone's sdk part, as at f30dee54)

Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
2026-11-13 12:49:56 +01:00

34 lines
1.4 KiB
Go

package seatlist
import (
"encoding/json"
"errors"
"strings"
"testing"
)
func TestHolderOf(t *testing.T) {
answer := `{"seats":[{"seat":"other","holders":[{"module":"x"}]},{"seat":"mesh-provisioner","holders":[{"module":"prov"},{"module":"second"}]}]}`
for _, row := range []struct {
name, seat, want, err string
call HolderCaller
}{
{"the first holder on record", "mesh-provisioner", "prov", "", func(k string, b any) (json.RawMessage, error) {
if k != "seat:mesh-module-assigner.assignments" || b.(map[string]string)["seats"] != "true" {
t.Errorf("asked %q with %v", k, b)
}
return json.RawMessage(answer), nil
}},
{"no holder", "absent", "", "no module holds the seat absent", func(string, any) (json.RawMessage, error) { return json.RawMessage(answer), nil }},
{"the ask fails", "x", "", "who holds the seat x is not asked", func(string, any) (json.RawMessage, error) { return nil, errors.New("down") }},
{"not the holders' answer", "x", "", "is not the seat holders'", func(string, any) (json.RawMessage, error) { return json.RawMessage(`nope`), nil }},
} {
t.Run(row.name, func(t *testing.T) {
got, err := HolderOf(row.call, row.seat)
if row.err == "" && (err != nil || got != row.want) || row.err != "" && (err == nil || !strings.Contains(err.Error(), row.err)) {
t.Errorf("HolderOf = %q, %v; want %q, %q", got, err, row.want, row.err)
}
})
}
}