ADR 0593 §7: the composer with its refusals leaves mesh-sdk, so mesh-sdk carries no composition rule. The catalogue functions only the node-engine's composition reaches (Resolve, Resolution's Compose, Declaration, DataItems, LeftOut, Rules and the rest, the settings, placeholder and template refusals, the rendering helpers) are copied with their tests into internal/compose/resolution; a method of a mesh-sdk shape becomes a function taking it first. The composition calls its own copies, and the captured catalogue its tests read lives here now, shared by mesh-compose's tests. Claude-Session: https://claude.ai/code/session_01NcbgfJ9Gum47zkFKWRaovL
81 lines
3.4 KiB
Go
81 lines
3.4 KiB
Go
package resolution
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
mcat "git.novox.be/novox/mesh-sdk/go/catalogue"
|
|
)
|
|
|
|
func onRecord(node, module string) []mcat.Held {
|
|
return []mcat.Held{{Claim: "mesh-broker", Scope: mcat.ScopeMesh, Node: node, Module: module}}
|
|
}
|
|
|
|
// 1317/AC1
|
|
func TestASeatWhoseHolderIsAssignedNowhereIsPassedToItsOnlyClaimant(t *testing.T) {
|
|
busSeatDelivering(t, "mesh-bus")
|
|
passes, said := SeatsToPassOn(onRecord("novox", "old-broker"),
|
|
[]mcat.Assignment{{Node: "novox", Manifest: newBroker()}})
|
|
if len(said) != 0 || len(passes) != 1 {
|
|
t.Fatalf("the only claimant was not given the seat: passes=%v said=%v", passes, said)
|
|
}
|
|
p := passes[0]
|
|
if p.Seat.Name != "mesh-broker" || p.From.Module != "old-broker" || p.From.Node != "novox" ||
|
|
p.To.Module != "new-broker" || p.To.Node != "novox" {
|
|
t.Fatalf("the pass does not name the seat, the former holder and the new one: %+v", p)
|
|
}
|
|
}
|
|
|
|
// 1317/AC2
|
|
func TestWithTwoClaimantsAndTheHolderGoneNothingIsPassedAndTheRefusalNamesBoth(t *testing.T) {
|
|
busSeatDelivering(t, "mesh-bus")
|
|
passes, said := SeatsToPassOn(onRecord("novox", "gone"), []mcat.Assignment{
|
|
{Node: "novox", Manifest: newBroker()}, {Node: "ace", Manifest: oldBroker()}})
|
|
if len(passes) != 0 || len(said) != 1 {
|
|
t.Fatalf("two claimants: passes=%v said=%v", passes, said)
|
|
}
|
|
for _, want := range []string{"old-broker", "new-broker", "seat mesh-broker --to"} {
|
|
if !strings.Contains(said[0], want) {
|
|
t.Fatalf("the refusal does not say %q: %s", want, said[0])
|
|
}
|
|
}
|
|
}
|
|
|
|
// 1317/AC3
|
|
func TestAHolderStillAssignedSomewhereChangesNothing(t *testing.T) {
|
|
busSeatDelivering(t, "mesh-bus")
|
|
// Assigned on another machine than the record names: still assigned somewhere.
|
|
passes, said := SeatsToPassOn(onRecord("novox", "old-broker"), []mcat.Assignment{
|
|
{Node: "ace", Manifest: oldBroker()}, {Node: "novox", Manifest: newBroker()}})
|
|
if len(passes) != 0 || len(said) != 0 {
|
|
t.Fatalf("a holder still assigned lost its seat: passes=%v said=%v", passes, said)
|
|
}
|
|
}
|
|
|
|
// 1317/AC4
|
|
func TestWithNoClaimantTheRecordStays(t *testing.T) {
|
|
busSeatDelivering(t, "mesh-bus")
|
|
passes, said := SeatsToPassOn(onRecord("novox", "old-broker"), []mcat.Assignment{
|
|
{Node: "novox", Manifest: mcat.Manifest{Module: "other"}}})
|
|
if len(passes) != 0 || len(said) != 0 {
|
|
t.Fatalf("with no claimant: passes=%v said=%v", passes, said)
|
|
}
|
|
// A claimant that cannot hold the seat (it does not provide what the seat delivers) is no claimant.
|
|
bad := mcat.Manifest{Module: "no-bus", Claims: []mcat.Claim{{Name: "mesh-broker", Scope: mcat.ScopeMesh}}}
|
|
passes, said = SeatsToPassOn(onRecord("novox", "old-broker"), []mcat.Assignment{{Node: "novox", Manifest: bad}})
|
|
if len(passes) != 0 || len(said) != 0 {
|
|
t.Fatalf("a module that cannot hold the seat was passed it: passes=%v said=%v", passes, said)
|
|
}
|
|
}
|
|
|
|
// A replicated seat is never passed: its holders are added by an act (ADR 0223).
|
|
func TestAReplicatedSeatIsNeverPassed(t *testing.T) {
|
|
record := []mcat.Held{{Claim: "mesh-dns-resolver", Scope: mcat.ScopeMesh, Node: "novox", Module: "gone"}}
|
|
resolver := mcat.Manifest{Module: "resolver", Provides: []mcat.Offer{{Name: "wildcard-resolution", Scope: mcat.ScopeMesh}},
|
|
Claims: []mcat.Claim{{Name: "mesh-dns-resolver", Scope: mcat.ScopeMesh}}}
|
|
passes, _ := SeatsToPassOn(record, []mcat.Assignment{{Node: "novox", Manifest: resolver}})
|
|
if len(passes) != 0 {
|
|
t.Fatalf("a replicated seat was passed: %v", passes)
|
|
}
|
|
}
|