package manifests import ( "os" "path/filepath" "strings" "testing" ) // The tree's manifests are ones a judge can read, and no module is named twice. A row is a catalogue of its own: a // manifest that is no JSON and two manifests of one module are refused, naming the file; a manifest with a field this // check does not know is not (it judges nothing: the checker does, ADR 0578 ยง2). The catalogue itself passes. func TestEveryManifestDecodesAndNamesOneModule(t *testing.T) { for _, row := range []struct { name string files map[string]string refused string }{ {name: "a manifest the judge can read", files: map[string]string{"a": `{"module":"a","version":"1"}`}}, {name: "a field no part knows is the judge's to refuse", files: map[string]string{"a": `{"module":"a","version":"1","unheard":true}`}}, {name: "bytes that are no manifest", files: map[string]string{"a": `{"module":`}, refused: "modules/a/module.json"}, {name: "two manifests of one module", files: map[string]string{"a": `{"module":"x","version":"1"}`, "b": `{"module":"x","version":"1"}`}, refused: "two manifests name one module"}, } { root := t.TempDir() for dir, manifest := range row.files { if err := os.MkdirAll(filepath.Join(root, "modules", dir), 0o755); err != nil { t.Fatal(err) } if err := os.WriteFile(filepath.Join(root, "modules", dir, "module.json"), []byte(manifest), 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 no judge can read:\n%s", strings.Join(real, "\n")) } }