package main import ( "os" "path/filepath" "strings" "testing" ) // The catalogue's placement files as the merge check reads them (ADR 0549 §1, ADR 0555): the real tree holds every // rule, and a tree that breaks them is refused with every finding named at once. func TestPlacementFiles(t *testing.T) { found, err := Check("../..") if err != nil { t.Fatal(err) } for _, f := range found { t.Errorf("%s (novox/hq ADR 0549 §1)", f) } root := t.TempDir() write := func(name, body string) { t.Helper() if err := os.MkdirAll(filepath.Join(root, "placement"), 0o755); err != nil { t.Fatal(err) } if err := os.WriteFile(filepath.Join(root, "placement", name), []byte(body), 0o644); err != nil { t.Fatal(err) } } if found, err := Check(root); err != nil || len(found) != 0 { t.Fatalf("a catalogue with no placement directory: %v, %v", found, err) } write("ace.json", `{"v":1,"node":"ace","decided":{"hub":true,"address":"10.77.0.1"},"modules":[{"module":"a","ports":{"80":8080}},{"module":"b","ports":{"81":8080}}]}`) write("g14.json", `{"v":1,"node":"g14","decided":{"hub":true,"address":"10.77.0.1"},"modules":[{"module":"c","bindings":{"pg":{"node":"ace","module":"pg"}}}]}`) write("novox.json", `{"v":1,"node":"shanks","modules":[]}`) write("bad.json", `{"v":1,"node":"bad","modules":{}}`) write("dated.json", `{"v":1,"node":"dated","revision":"abc","modules":[]}`) write("notes.md", "x") found, err = Check(root) if err != nil { t.Fatal(err) } for _, want := range []string{"a and b are both published on host port 8080", "bound to ace/pg", "both have the address 10.77.0.1", "ace, g14 are each placed as it", "placement file of novox names the node", "bad.json does not read", "dated.json names a revision", "notes.md is not a placement file"} { hit := false for _, f := range found { hit = hit || strings.Contains(f, want) } if !hit { t.Errorf("no finding says %q; found %v", want, found) } } }