package catalogue import ( "path/filepath" "sync" "testing" ) // readManifest is one manifest of the catalogue as ReadTreeManifest read it. type readManifest struct { path string // the module.json manifest Manifest err error } var ( readOnce sync.Once readAll []readManifest readRoot string ) // catalogueManifests is every manifest of the catalogue (catalogueRoot), read through ReadTreeManifest once // per test binary and not once per test: the checks over the real catalogue each read and parsed every // manifest again, and together took 1.5 s of mesh-sdk's unit bound of 2 s (issue 1756). What it returns is // shared and read-only: a test that changes a manifest copies it first. func catalogueManifests(t *testing.T) (string, []readManifest) { t.Helper() root := catalogueRoot(t) readOnce.Do(func() { readRoot = root found, err := filepath.Glob(filepath.Join(root, "modules", "*", "module.json")) if err != nil { return } for _, p := range found { m, err := ReadTreeManifest(root, filepath.Dir(p)) readAll = append(readAll, readManifest{path: p, manifest: m, err: err}) } }) if len(readAll) == 0 { t.Fatalf("no manifests under %s", root) } return readRoot, readAll }