package provision import "testing" // SharedInstanceEligibility must be the reconciler's own predicates, never a // second reading of the environment (spec §6.1, codex R3-3). func TestSharedInstanceEligibilityIsTheMintPredicate(t *testing.T) { cases := []struct { pools []string inbound string shared, accept bool }{ {nil, "", true, true}, {[]string{"tito"}, "", false, true}, {[]string{"", "tito"}, "", true, true}, {nil, InboundNone, true, false}, {[]string{"tito"}, InboundNone, false, false}, } for _, c := range cases { cfg := ReconcileConfig{Pools: c.pools, Inbound: c.inbound} shared, inbound := cfg.SharedInstanceEligibility() if shared != poolServed(c.pools, "") || inbound != (c.inbound != InboundNone) { t.Fatalf("%+v: eligibility diverges from the mint predicates", c) } if shared != c.shared || inbound != c.accept { t.Fatalf("%+v: got (%v, %v), want (%v, %v)", c, shared, inbound, c.shared, c.accept) } } } // spec §16, codex plan-R3 4: each published answer pairs with the reconcile // pass's own behaviour on an ORDINARY record (the shared "" pool, routed). // A box that publishes both true mints it; a box that publishes either // false refuses it, so the console's eligibility never offers a region // whose box would refuse the record. func TestEligibilityPairsWithTheReconcileRefusal(t *testing.T) { for _, c := range []struct { pools []string inbound string }{ {nil, ""}, {[]string{"tito"}, ""}, {[]string{"", "tito"}, ""}, {nil, InboundNone}, {[]string{"tito"}, InboundNone}, } { s, sqid := setup(t) if err := PutManifest(ctx, s, sqid, "tito", Manifest{Schema: 1, App: "tito", Domain: "go.tito.io"}); err != nil { t.Fatal(err) } rec := acmeRecord(sqid) rec.Pool = "" if err := CreateRecord(ctx, s, rec); err != nil { t.Fatal(err) } reg := regWith(t) cfg := ReconcileConfig{Region: "ie", Pools: c.pools, DataDir: "/data", Inbound: c.inbound} if err := Reconcile(ctx, s, reg, cfg); err != nil { t.Fatal(err) } rt, err := reg.Get(rec.Host) minted := err == nil && rt != nil shared, inbound := cfg.SharedInstanceEligibility() if minted != (shared && inbound) { t.Errorf("pools %q inbound %q: minted %v, but the box publishes serves_shared_pool=%v accepts_inbound=%v", c.pools, c.inbound, minted, shared, inbound) } } }