89 lines
3.8 KiB
Go
89 lines
3.8 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-catalog/checks/trunk"
|
|
)
|
|
|
|
func TestFindingsRefuseWhatThePlacementPathLeft(t *testing.T) {
|
|
for _, row := range []struct {
|
|
name string
|
|
files map[string]string
|
|
want string // empty: clean
|
|
}{
|
|
{"clean", map[string]string{"modules/a/module.json": `{"module":"a","reads":["mesh-delivery-assigner.placement"]}`}, ""},
|
|
{"a placement directory", map[string]string{"placement/ace.json": `{}`}, "placement: the repository holds no placement"},
|
|
{"a particulars file", map[string]string{"particulars": "ace\n"}, "particulars: the repository lists no node names"},
|
|
{"a read of the indexer's placement", map[string]string{"modules/a/module.json": `{"module":"a","reads":["mesh-delivery-indexer.placement"]}`}, `a: names "mesh-delivery-indexer.placement"`},
|
|
{"a read of its candidates", map[string]string{"modules/b/module.json": `{"module":"b","reads":["mesh-delivery-indexer.placement-candidates"]}`}, "placement-candidates"},
|
|
{"its event", map[string]string{"modules/c/module.json": `{"module":"c","on":[{"event":"mesh-delivery-indexer.placement-changed"}]}`}, "placement-changed"},
|
|
// Issue 774 (ADR 0549 §3, §6): a reader of the controller's assignments is refused unless the list names it, the
|
|
// controller's own manifest is not judged, and a name on the list whose module no longer reads them is refused.
|
|
{"an unlisted reader of the assignments", map[string]string{"modules/r/module.json": `{"module":"r","reads":["mesh-controller.assignments"]}`}, "r reads mesh-controller.assignments"},
|
|
{"a listed reader and the controller", map[string]string{"modules/l/module.json": `{"module":"l","reads":["mesh-controller.assignments"]}`,
|
|
"modules/mesh-controller/module.json": `{"module":"mesh-controller","reads":["mesh-controller.assignments"]}`, Allowed: "# why\nl its plan\n"}, ""},
|
|
{"a listed module that reads them no more", map[string]string{Allowed: "gone no longer reads\n"}, "names gone, which no longer reads"},
|
|
{"the seat's own state is allowed", map[string]string{"modules/d/module.json": `{"module":"d","reads":["mesh-placement.placement"]}`}, ""},
|
|
} {
|
|
t.Run(row.name, func(t *testing.T) {
|
|
root := t.TempDir()
|
|
for path, text := range row.files {
|
|
p := filepath.Join(root, path)
|
|
if err := os.MkdirAll(filepath.Dir(p), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(p, []byte(text), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
got, err := Findings(root)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if all := strings.Join(got, "\n"); (row.want == "") != (all == "") || !strings.Contains(all, row.want) {
|
|
t.Fatalf("findings = %q, want one containing %q", all, row.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// The script's run of this check over the real tree (novox/hq ADR 0529 clause 2).
|
|
func TestTheCatalogueHoldsNoPlacementOfTheRepositoryPath(t *testing.T) {
|
|
got, err := Findings(filepath.Join("..", ".."))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, f := range got {
|
|
t.Error(f)
|
|
}
|
|
// Issue 774 (ADR 0549 §3, §6; the comparison of novox/hq ADR 0529 clause 2): the list of modules still reading the
|
|
// controller's assignments gains none the trunk's copy at the merge base does not hold. Its first copy gains nothing.
|
|
path, ok := trunk.Copy(t, Allowed)
|
|
if !ok {
|
|
return
|
|
}
|
|
names := func(path string) map[string]bool {
|
|
raw, err := os.ReadFile(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
out := map[string]bool{}
|
|
for _, line := range strings.Split(string(raw), "\n") {
|
|
if f := strings.Fields(line); len(f) > 0 && !strings.HasPrefix(f[0], "#") {
|
|
out[f[0]] = true
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
base := names(path)
|
|
for module := range names(filepath.Join("..", "..", Allowed)) {
|
|
if !base[module] {
|
|
t.Errorf("%s gains %s, which the trunk's copy does not hold: the list only shrinks", Allowed, module)
|
|
}
|
|
}
|
|
}
|