Give a module's own credential its dial, subjects and durable consumer in mesh-sdk, so a part no longer hand-writes them (issue 1242)

This commit is contained in:
2026-10-27 20:36:14 +01:00
parent a262c7dbe0
commit 3236cbad43
2 changed files with 127 additions and 0 deletions
+36
View File
@@ -257,3 +257,39 @@ func (h *heldSubscriber) deliver() {
h.mu.Unlock()
handle(&nats.Msg{Subject: subject})
}
// 1242: the module's own credential gives the names it reaches on the bus (its events' subjects, its own
// stream's, its durable consumer's) and the options it dials with.
func TestModuleAccountNamesAndDialOptions(t *testing.T) {
a := Account{URL: "nats://x:4222", Node: "n1", Module: "mesh-delivery-teller", User: "n1.mesh-delivery-teller", Password: "pw"}
for _, c := range []struct{ name, got, want string }{
{"event subject", a.EventSubject("put"), "mesh.mod.mesh-delivery-teller.event.put"},
{"own stream subject", a.StreamSubject("forge.x.pull"), "mesh.stream.mesh-delivery-teller.event.forge.x.pull"},
{"durable consumer", a.EventConsumerName(), "n1_mesh-delivery-teller"},
} {
if c.got != c.want {
t.Errorf("%s: got %q, want %q", c.name, c.got, c.want)
}
}
if _, err := ReadBrokerAccount(func(string) string { return " " }); err == nil || !strings.Contains(err.Error(), BrokerFileEnv) {
t.Errorf("no broker file set: %v", err)
}
var o nats.Options
for _, opt := range a.DialOptions() {
if err := opt(&o); err != nil {
t.Fatal(err)
}
}
if o.Name != "n1.mesh-delivery-teller" || o.User != "n1.mesh-delivery-teller" ||
o.MaxReconnect != -1 || !o.RetryOnFailedConnect || o.Secure {
t.Errorf("dial options: %+v", o)
}
a.Fingerprint = "sha256:ab"
o = nats.Options{}
for _, opt := range a.DialOptions() {
_ = opt(&o)
}
if !o.Secure || o.TLSConfig == nil {
t.Errorf("a fingerprint did not pin the connection")
}
}