package manifests import ( "os" "path/filepath" "strings" "testing" ) // Every manifest of the catalogue is one the nodes can use, and the catalogue holds together as one shelf. A row is a // manifest written into a catalogue of its own: power's bar item as mesh-catalog ca8d6f33 gave it (issue 774) is // refused naming the attribute, and the same item without it passes. func TestEveryManifestIsOneTheNodesCanUse(t *testing.T) { for _, row := range []struct { name, attributes, refused string }{ {name: "the bar places by bar and place", attributes: `"bar":"bottom","place":"status","order":"45"`}, {name: "an attribute the bar places by none of (ca8d6f33)", attributes: `"bar":"bottom","place":"status","order":"45","shows":"state","state":"power.draw"`, refused: `"shows" is none of them`}, } { root := t.TempDir() dir := filepath.Join(root, "modules", "bar-user") if err := os.MkdirAll(filepath.Join(dir, "files"), 0o755); err != nil { t.Fatal(err) } manifest := `{"module":"bar-user","version":"1","moved":true,` + `"build":{"artifacts":[{"name":"files","kind":"archive","from":"files"}]},` + `"items":[{"collection":"contribution:node-bar:block","attributes":{` + row.attributes + `},"template":"files/bar"}]}` for path, body := range map[string]string{"module.json": manifest, "files/bar": "{\"shows\":\"command\"}\n"} { if err := os.WriteFile(filepath.Join(dir, path), []byte(body), 0o644); err != nil { t.Fatal(err) } } got, err := Problems(root) if err != nil { t.Fatal(err) } joined := strings.Join(got, "\n") if (row.refused == "") != (len(got) == 0) || !strings.Contains(joined, row.refused) { t.Errorf("%s: refused %q, want %q", row.name, joined, row.refused) } } real, err := Problems(filepath.Join("..", "..")) if err != nil { t.Fatal(err) } if len(real) != 0 { t.Fatalf("the catalogue holds manifests the nodes cannot use:\n%s", strings.Join(real, "\n")) } }