package buscompose import ( "encoding/json" "git.novox.be/novox/mesh-sdk/go/catalogue" "os" "slices" "strings" "testing" ) // namesAreTheManifests (a subtest of TestTheCopiedComposerComposesAsTheControllers): the holders and states of other parts that the grants part names are the ones its manifest // lists in `reads` and `invokes` (no contract names a holder: novox/hq ADR 0634 ยง1), and a state's bucket is its holder's // name and the state's. func namesAreTheManifests(t *testing.T) { raw, err := os.ReadFile("../../module.json") if err != nil { t.Fatal(err) } var m struct { Module string `json:"module"` Reads []string `json:"reads"` Invokes []string `json:"invokes"` } if err := json.Unmarshal(raw, &m); err != nil { t.Fatal(err) } if m.Module != GrantsModule { t.Errorf("the manifest's module is %q, the part names itself %q", m.Module, GrantsModule) } for _, c := range []struct{ list, name, bucket string }{ {"reads", HaveBucket[:strings.Index(HaveBucket, "_")] + ".have", HaveBucket}, {"reads", NodeLoginsRead, NodeLoginsBucket}, {"reads", EnrolmentsRead, EnrolmentsBucket}, {"invokes", PlacementRead, PlacementBucket}, {"invokes", AssignerModule + ".wants", AssignerWantsBucket}, {"invokes", IndexerModule + ".modules", ModulesBucket}, {"invokes", IndexerModule + ".manifests", ManifestsBucket}, {"invokes", IndexerModule + ".verdicts", VerdictsBucket}, } { list := m.Reads if c.list == "invokes" { list = m.Invokes } if !slices.Contains(list, c.name) { t.Errorf("the part names %s, its manifest's %s are %v", c.name, c.list, list) } if got := strings.Replace(c.name, ".", "_", 1); got != c.bucket { t.Errorf("%s is kept in %s, the part names the bucket %s", c.name, got, c.bucket) } } } // busGrantsAreTheDeclared (a subtest of TestTheCopiedComposerComposesAsTheControllers): a removal is its grants, the leftovers' for // the nodes given too, one outside the set is refused, and the watchman hears the self-check's word and the dead letters; // the functions are the grants part's published package busgrants'. func busGrantsAreTheDeclared(t *testing.T) { got, err := BusRemovalGrants([]string{catalogue.RemovesEngineActs, catalogue.RemovesControllerLeftovers}, []string{"novox", "a b"}) if err != nil { t.Fatal(err) } for _, want := range []string{"$KV.mesh-host_acts.>", "$JS.API.CONSUMER.DELETE.EVENTS.controller", "$JS.API.CONSUMER.DELETE.EVENTS.novox_mesh-host", "$JS.API.STREAM.DELETE.OBJ_declaration-files-novox", "$JS.API.STREAM.DELETE.KV_mesh-controller_lease", "$JS.API.STREAM.DELETE.ASSIGNMENTS"} { if !slices.Contains(got, want) { t.Errorf("the grants lack %s", want) } } if slices.ContainsFunc(got, func(s string) bool { return s == "$JS.API.STREAM.DELETE.OBJ_declaration-files-a b" || s == "$JS.API.CONSUMER.DELETE.EVENTS.a b_mesh-host" }) { t.Errorf("a node name that is not a subject token widened the grants: %v", got) } if _, err := BusRemovalGrants([]string{"everything"}, nil); err == nil { t.Error("a removal outside the set was granted") } if hears := WatchmanHears(); !slices.Contains(hears, "mesh.seat.mesh-self-check.event.checked") || !slices.Contains(hears, "mesh.events.dead.>") { t.Errorf("the watchman hears %v", hears) } }