91 lines
3.0 KiB
Go
91 lines
3.0 KiB
Go
package broker
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func hasSubject(list []string, s string) bool {
|
|
for _, x := range list {
|
|
if x == s {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func composedFor(t *testing.T, module string) (pub, sub []string) {
|
|
t.Helper()
|
|
perms, err := PermissionsFor(Principal{Kind: KindModule, Node: "one", Module: module})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return perms.Publish, perms.Subscribe
|
|
}
|
|
|
|
func TestTheWatchmanHearsTheBuildSeatsAsksByName(t *testing.T) { // 1887/A8b
|
|
_, sub := composedFor(t, WatchmanModule)
|
|
for _, lang := range []string{"go", "node", "image"} {
|
|
for _, kind := range []string{"delivery", "check", "recheck"} {
|
|
if s := "mesh.seat.node-build-" + lang + ".accept." + kind; !hasSubject(sub, s) {
|
|
t.Errorf("the watchman cannot subscribe %s", s)
|
|
}
|
|
}
|
|
}
|
|
for _, s := range sub {
|
|
if strings.Contains(s, "node-build") && (strings.HasSuffix(s, ">") || strings.HasSuffix(s, "*")) {
|
|
t.Errorf("a wildcard over the build seats: %s", s)
|
|
}
|
|
}
|
|
pub, _ := composedFor(t, WatchmanModule)
|
|
for _, s := range pub {
|
|
if strings.Contains(s, "node-build") || strings.Contains(s, "SEAT_NODE_BUILD") {
|
|
t.Errorf("the watchman may publish on %s", s)
|
|
}
|
|
}
|
|
perms, _ := PermissionsFor(Principal{Kind: KindModule, Node: "one", Module: WatchmanModule})
|
|
if MayPublish(perms, "mesh.seat.node-build-go.accept.check") {
|
|
t.Error("the watchman may publish an ask")
|
|
}
|
|
// no other module hears them
|
|
if _, other := composedFor(t, "shop"); containsAny(other, "node-build") {
|
|
t.Errorf("another module hears the build seats: %v", other)
|
|
}
|
|
}
|
|
|
|
func containsAny(list []string, sub string) bool {
|
|
for _, x := range list {
|
|
if strings.Contains(x, sub) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func TestTheViewReadsTheBuildSeatsWorkersByNameAndPublishesNoAsk(t *testing.T) { // 1887/A8a
|
|
pub, sub := composedFor(t, ViewModule)
|
|
for _, s := range []string{
|
|
"$JS.API.STREAM.INFO.SEAT_NODE_BUILD_GO", "$JS.API.STREAM.MSG.GET.SEAT_NODE_BUILD_GO",
|
|
"$JS.API.CONSUMER.INFO.SEAT_NODE_BUILD_GO_CHECK_worker", "$JS.API.CONSUMER.INFO.SEAT_NODE_BUILD_NODE_RECHECK_worker",
|
|
"$JS.API.CONSUMER.INFO.SEAT_NODE_BUILD_IMAGE_DELIVERY_worker", "$JS.API.STREAM.MSG.GET.SEAT_NODE_BUILD_IMAGE",
|
|
} {
|
|
if !hasSubject(pub, s) {
|
|
t.Errorf("the view cannot request %s", s)
|
|
}
|
|
}
|
|
for _, s := range append(append([]string{}, pub...), sub...) {
|
|
if strings.Contains(s, "mesh.seat.node-build") || (strings.Contains(s, "NODE_BUILD") && (strings.Contains(s, "MSG.NEXT") || strings.Contains(s, "$JS.ACK") || strings.Contains(s, "CONSUMER.CREATE"))) {
|
|
t.Errorf("the view may publish an ask or pull and acknowledge: %s", s)
|
|
}
|
|
}
|
|
perms, _ := PermissionsFor(Principal{Kind: KindModule, Node: "one", Module: ViewModule})
|
|
for _, s := range []string{"mesh.seat.node-build-go.accept.check", "$JS.API.CONSUMER.MSG.NEXT.SEAT_NODE_BUILD_GO.SEAT_NODE_BUILD_GO_CHECK_worker"} {
|
|
if MayPublish(perms, s) {
|
|
t.Errorf("the view may publish %s", s)
|
|
}
|
|
}
|
|
if other, _ := composedFor(t, "shop"); containsAny(other, "SEAT_NODE_BUILD") {
|
|
t.Errorf("another module reads the build seats: %v", other)
|
|
}
|
|
}
|