50 lines
2.2 KiB
Go
50 lines
2.2 KiB
Go
package groups
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
|
|
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery"
|
|
)
|
|
|
|
// The seat answers the whole list of groups with more than one bus message carries once many have ended (live 02:06);
|
|
// a read of the open ones, or of one by its id, is answered; Read never asks for all (lead: principle 7).
|
|
func TestReadsNeverAskTheEndedGroupsWhole(t *testing.T) {
|
|
const bus = 1 << 20
|
|
seatOf := func(_ context.Context, _ string, body any) (json.RawMessage, error) {
|
|
in := body.(seat.GroupsInput)
|
|
groups := []seat.Group{{ID: "feat/open", State: "gathering"}}
|
|
switch {
|
|
case in.Group != "":
|
|
groups = []seat.Group{{ID: in.Group}}
|
|
case in.All == seat.GroupsInputAllTrue:
|
|
for i := 0; i < 3000; i++ {
|
|
groups = append(groups, seat.Group{ID: "ended", Why: strings.Repeat("x", 500)})
|
|
}
|
|
}
|
|
raw, _ := json.Marshal(seat.GroupsAnswer{Groups: groups})
|
|
if len(raw) > bus {
|
|
return nil, errors.New("the answer is more than the bus carries in one message")
|
|
}
|
|
return raw, nil
|
|
}
|
|
if got, err := Read(context.Background(), seatOf); err != nil || len(got) != 1 || got[0].ID != "feat/open" {
|
|
t.Errorf("Read: %v %v; want the open group alone", got, err)
|
|
}
|
|
if got, err := ReadGroup(context.Background(), seatOf, "feat/ended"); err != nil || len(got) != 1 || got[0].ID != "feat/ended" {
|
|
t.Errorf("ReadGroup: %v %v; want the group by its id", got, err)
|
|
}
|
|
if _, err := ReadAll(context.Background(), seatOf); err == nil {
|
|
t.Errorf("ReadAll: want the seat's refusal to be an error, never read as no group")
|
|
}
|
|
// A member the seat names twice is said once, at its later head (2026-11-14: the take-in of every repository with a
|
|
// branch of that group was refused whole).
|
|
twice := seat.Group{ID: "feat/twice", Members: []seat.Member{{Repository: "o/a", Number: 1, Head: "old"}, {Repository: "o/b", Number: 2, Head: "b"}, {Repository: "o/a", Number: 1, Head: "new"}}}
|
|
if got := MembersOf(twice); len(got) != 2 || got[0].Repository != "o/a" || got[0].Head != "new" || got[1].Repository != "o/b" {
|
|
t.Errorf("MembersOf a group naming o/a#1 twice = %+v, want o/a#1 at new, then o/b#2", got)
|
|
}
|
|
}
|