package bus import ( "errors" "fmt" "testing" ) func TestSubjectsAreTheOnesTheTypeScriptRuntimeUses(t *testing.T) { for key, want := range map[string]string{ "status": "mesh.mod.self.tool.status", "alpha.one": "mesh.mod.alpha.tool.one", "alpha.one@anchor": "mesh.mod.alpha.tool.one.anchor", "seat:node-shelf.list": "mesh.seat.node-shelf.tool.list", "seat:node-shelf.list@anchor": "mesh.seat.node-shelf.tool.list.anchor", } { if got, err := ToolSubject(key, "self"); err != nil || got != want { t.Errorf("%s: %s %v, want %s", key, got, err, want) } } if _, err := ToolSubject("seat:nothing", "self"); err == nil { t.Error("a seat with no verb was accepted") } if SeatToolSubject("s", "v", "node", "n") != "mesh.seat.s.tool.v.n" || SeatToolSubject("s", "v", "mesh", "n") != "mesh.seat.s.tool.v" { t.Error("seat subjects") } } func TestAFingerprintIsReadHoweverItIsWritten(t *testing.T) { for _, f := range []string{"sha256:AB:CD:ef", "abcdef", "ABCDEF", "SHA256:abcdef"} { if got := normalizeFingerprint(f); got != "abcdef" { t.Errorf("%s → %s", f, got) } } } func TestWhatWaitingCannotFixIsFinal(t *testing.T) { for err, want := range map[error]string{ fmt.Errorf("x509: %w: it presented aa", ErrPin): "the bus's certificate does not match the pin", errors.New("nats: Authorization Violation"): "the bus refused this account", errors.New("nats: invalid url"): "the bus address is not a usable URL", errors.New("dial tcp 10.0.0.1:4222: connect: connection refused"): "", } { if got := Fatal(err); got != want { t.Errorf("%v → %q, want %q", err, got, want) } } } // An event given up on and delivered again by the controller arrives under `mesh.again..` and // the event's own subject without its `mesh.` (novox/hq issue 330): the handler sees the key it saw the // first time, for a module's event and a seat's. func TestAnEventDeliveredAgainHasItsOwnKey(t *testing.T) { for original, again := range map[string]string{ "mesh.mod.gitea.event.pull.merged": "mesh.again.ace_sonarr.mod.gitea.event.pull.merged", "mesh.seat.node-build-agent.event.built": "mesh.again.ace_sonarr.seat.node-build-agent.event.built", } { if keyOf(again) != keyOf(original) { t.Errorf("%s reads as %q, the event as %q", again, keyOf(again), keyOf(original)) } } }