Builds: design 47 G A-369 (G-22-lead-answers-2.md) Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
52 lines
1.6 KiB
Go
52 lines
1.6 KiB
Go
package grants
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
|
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
|
"git.novox.be/novox/mesh-sdk/go/views"
|
|
)
|
|
|
|
type wiring struct{ followers []*views.Follower }
|
|
|
|
func (w *wiring) Adopt(f *views.Follower, _, _ string, _ func(context.Context, []byte) error) error {
|
|
w.followers = append(w.followers, f)
|
|
return nil
|
|
}
|
|
func (w *wiring) Drop(string, string) error { return nil }
|
|
|
|
// Design 47 G A-369: the grants part's wait for its catalog half asks the catalog client's Ready, so a mesh whose registrations
|
|
// and gate's source are answered and name no branch is none-yet for grants, and waits while either is not answered.
|
|
func TestAMeshThatNamesNoBranchIsNoWaitForGrants(t *testing.T) {
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
defer cancel()
|
|
call := func(key string, _ any) (json.RawMessage, error) {
|
|
if key == meshcatalogclient.RegistrationsVerb {
|
|
return json.Marshal(seat.RegistrationsAnswer{Registrations: []seat.Registration{}})
|
|
}
|
|
return json.Marshal(map[string][]string{"branches": {}})
|
|
}
|
|
for _, answered := range []bool{false, true} {
|
|
w := &wiring{}
|
|
b, err := meshcatalogclient.NewBranches(w, call)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if answered {
|
|
for _, f := range w.followers {
|
|
if err := f.Start(ctx); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
}
|
|
got := (&CatalogOf{Branches: b, Context: ctx}).Waiting()
|
|
if (len(got) == 0) != answered {
|
|
t.Errorf("answered %v: waiting %v", answered, got)
|
|
}
|
|
}
|
|
}
|