package buildrun import ( "context" "encoding/json" "errors" "testing" "time" "git.novox.be/novox/mesh-sdk/go/seatlist" ) // The builder and the checker find the assigner's holder at run time: asked again while the seat list does not answer, and the names of the view // are made from the holder (design 47 G A-119), not fixed in code. func TestTheAssignerHolderIsFoundAtRunTime(t *testing.T) { asks, slept := 0, 0 call := func(key string, _ any) (json.RawMessage, error) { if key != seatlist.HolderKey() { t.Errorf("asked %q, want %q", key, seatlist.HolderKey()) } if asks++; asks == 1 { return nil, errors.New("down") } return json.RawMessage(`{"seats":[{"seat":"mesh-module-assigner","holders":[{"module":"acme-assigner"}]}]}`), nil } holder, ok := AssignerHolder(context.Background(), call, time.Second, func(context.Context, time.Duration) bool { slept++; return true }, func(string, ...any) {}) if !ok || holder != "acme-assigner" || slept != 1 { t.Fatalf("holder = %q, %v after %d pauses, want acme-assigner after one", holder, ok, slept) } if n := AssignmentsOf(holder); n.Tool != "acme-assigner.assignments" || n.Bucket != "acme-assigner_assignments" { t.Errorf("names = %+v", n) } if _, ok := AssignerHolder(context.Background(), func(string, any) (json.RawMessage, error) { return nil, errors.New("down") }, time.Second, func(context.Context, time.Duration) bool { return false }, func(string, ...any) {}); ok { t.Error("a holder was found though ctx ended") } }