82 lines
3.3 KiB
Go
82 lines
3.3 KiB
Go
package catalogue
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// **A seat held once whose holder on record is assigned nowhere passes to its only claimant** (novox/hq ADR
|
|
// 0449 §4, issue 1317).
|
|
|
|
func onRecord(node, module string) []Held {
|
|
return []Held{{Claim: "mesh-broker", Scope: ScopeMesh, Node: node, Module: module}}
|
|
}
|
|
|
|
// 1317/AC1
|
|
func TestASeatWhoseHolderIsAssignedNowhereIsPassedToItsOnlyClaimant(t *testing.T) {
|
|
busSeatDelivering(t, "mesh-bus")
|
|
passes, said := SeatsToPassOn(onRecord("novox", "old-broker"),
|
|
[]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"), []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"), []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"), []Assignment{
|
|
{Node: "novox", Manifest: 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 := Manifest{Module: "no-bus", Claims: []Claim{{Name: "mesh-broker", Scope: ScopeMesh}}}
|
|
passes, said = SeatsToPassOn(onRecord("novox", "old-broker"), []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 := []Held{{Claim: "mesh-dns-resolver", Scope: ScopeMesh, Node: "novox", Module: "gone"}}
|
|
resolver := Manifest{Module: "resolver", Provides: []Offer{{Name: "wildcard-resolution", Scope: ScopeMesh}},
|
|
Claims: []Claim{{Name: "mesh-dns-resolver", Scope: ScopeMesh}}}
|
|
passes, _ := SeatsToPassOn(record, []Assignment{{Node: "novox", Manifest: resolver}})
|
|
if len(passes) != 0 {
|
|
t.Fatalf("a replicated seat was passed: %v", passes)
|
|
}
|
|
}
|