process.Conn.Keeps, stdio.Keeps and the TypeScript keeps publish the announcement on the module's own subject; afterwards a state the code did not announce is refused at the call, so announcement and code cannot drift. The package goes to 0.1.15 for keeps.
46 lines
1.5 KiB
Go
46 lines
1.5 KiB
Go
//go:build integration
|
|
|
|
package process
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/nats-io/nats.go/jetstream"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/announce"
|
|
)
|
|
|
|
// 1790/S10: on a real bus, a process's Keeps lands on its module's own announcement subject, in the events stream, as
|
|
// the module's announcement; a state it did not announce is then refused at the call.
|
|
func TestAProcessAnnouncesWhatItKeepsOnTheBus(t *testing.T) {
|
|
url, account := grantedSendProcess(t)
|
|
_, admin := adminJS(t, url)
|
|
stream, err := admin.CreateStream(ctxFor(t), jetstream.StreamConfig{Name: "MAIL_STATES", Subjects: []string{announce.Subject("mesh-mail")}})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
conn, err := Connect(account)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer conn.Close()
|
|
if err := conn.Keeps(announce.State{Name: "accounts", Readable: true}, announce.State{Name: "drafts"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
msg, err := stream.GetMsg(ctxFor(t), 1)
|
|
if err != nil {
|
|
t.Fatalf("no announcement in the stream: %v", err)
|
|
}
|
|
if msg.Subject != "mesh.mod.mesh-mail.event.states" || msg.Header.Get("x-source") != "mesh-mail" {
|
|
t.Fatalf("announced on %s with %v", msg.Subject, msg.Header)
|
|
}
|
|
got, err := announce.Decode(msg.Data)
|
|
if err != nil || !got.Readable("accounts") || !got.Keeps("drafts") || got.Readable("drafts") || got.Node != "novox" {
|
|
t.Fatalf("announced %s (%v)", msg.Data, err)
|
|
}
|
|
if _, err := conn.State("outbox").Get("k"); err == nil || !strings.Contains(err.Error(), `"outbox"`) {
|
|
t.Fatalf("an unannounced state was bound: %v", err)
|
|
}
|
|
}
|