//go:build integration package process import ( "testing" "time" "git.novox.be/novox/mesh-sdk/go/membership" ) // A process connected pinned to a test bus hears the membership published for its node and module, and // ignores what is not one (novox/hq issue 1633, AC2). func TestFollowMembershipHearsWhatIsIssuedToTheAccount(t *testing.T) { url, fingerprint := selfSignedServer(t) account := mailSenderAccount(t, url, fingerprint) conn, err := Connect(account) if err != nil { t.Fatal(err) } defer conn.Close() got := make(chan membership.Membership, 1) bad := make(chan error, 4) if err := conn.FollowMembership(func(m membership.Membership) { got <- m }, func(e error) { bad <- e }); err != nil { t.Fatal(err) } if err := conn.nc.Publish(membership.Subject("novox", "mesh-mail"), []byte("not json")); err != nil { t.Fatal(err) } if err := conn.nc.Publish(membership.Subject("novox", "mesh-mail"), []byte(`{"node":"novox","module":"mesh-mail","mesh":["10.0.0.1"]}`)); err != nil { t.Fatal(err) } select { case m := <-got: if m.Module != "mesh-mail" || len(m.Mesh) != 1 { t.Fatalf("membership: %+v", m) } case <-time.After(5 * time.Second): t.Fatal("no membership heard") } if len(bad) == 0 { t.Error("the body that is not a membership was not reported") } }