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) } } }