package meshtest import ( "encoding/json" "os" "path/filepath" "regexp" "strings" "testing" ) // **The bus the tests run is the bus the mesh runs** (novox/hq ADR 0227 rule 9, ADR 0237): the server linked // into the tests is held to the release the catalogue's bus image is — read from beside this checkout, as // the build seat clones it for a merge check — and, given the facts snapshot, to the release the mesh's bus // server says it runs. A bus upgrade moves the catalogue's pin; this then fails until go.mod's moves with it. func TestTheBusTheTestsRunIsTheBusTheMeshRuns(t *testing.T) { beside := os.Getenv("MESH_CHECK_BESIDE") if beside == "" { beside = filepath.Join("..", "..", "..", "..") } dockerfile := filepath.Join(beside, "mesh-catalog", "modules", "nats", "Dockerfile") raw, err := os.ReadFile(dockerfile) switch { case err == nil: pinned := regexp.MustCompile(`upstream: nats ([0-9.]+)-alpine`).FindSubmatch(raw) if pinned == nil { t.Fatalf("%s says no release its digest is", dockerfile) } if string(pinned[1]) != Version { t.Errorf("the tests run bus %s and the catalogue's bus image is %s: move go.mod's nats-server pin with the image", Version, pinned[1]) } case os.IsNotExist(err): t.Logf("the catalogue is not beside this checkout, so its bus image is not compared") default: t.Fatal(err) } path := os.Getenv("MESH_FACTS") if path == "" { t.Logf("no MESH_FACTS: the bus the mesh runs is compared in a merge check, which has it") return } body, err := os.ReadFile(path) if err != nil { t.Fatal(err) } var f struct { Taken string `json:"taken"` Versions struct { Bus string `json:"bus"` } `json:"versions"` } if err := json.Unmarshal(body, &f); err != nil { t.Fatal(err) } if f.Versions.Bus != "" && strings.TrimPrefix(f.Versions.Bus, "v") != Version { t.Errorf("the tests run bus %s and the mesh's bus runs %s (facts of %s)", Version, f.Versions.Bus, f.Taken) } } // Each test is given a bus of its own, and the same one at every ask. func TestEachTestHasABusOfItsOwn(t *testing.T) { var first string t.Run("one", func(t *testing.T) { first = URL(t) if URL(t) != first { t.Fatal("two buses for one test") } }) t.Run("two", func(t *testing.T) { if URL(t) == first { t.Fatal("two tests were given one bus") } }) } // What merge-check.sh said was "NOT TESTED HERE" is a skip with its reason: no node, or no package, each says so. func TestBundlesCannotBeLaunchedWithoutNodeOrTheSDKAndTheSkipSaysWhy(t *testing.T) { root := t.TempDir() if why := bundlesWhy(root, false); !strings.Contains(why, "node is not installed") { t.Errorf("no node said %q", why) } if why := bundlesWhy(root, true); !strings.Contains(why, "@novox/mesh-sdk") { t.Errorf("no package said %q", why) } if err := os.MkdirAll(filepath.Join(root, "node_modules", "@novox", "mesh-sdk"), 0o755); err != nil { t.Fatal(err) } if why := bundlesWhy(root, true); why != "" { t.Errorf("node and the package present said %q", why) } } // The checker runs node-tools' Go level by Go's convention and its Node level by package.json's test script // (novox/hq ADR 0529): no script of the repository's own runs beside them, and no module but node-tools is built from // here (ADR 0524 §5, the toolchain image retired). func TestTheRepositoryHoldsNoCheckScriptAndNodeToolsIsItsOnlyModule(t *testing.T) { root := filepath.Join("..", "..", "..") if _, err := os.Stat(filepath.Join(root, "merge-check.sh")); err == nil { t.Errorf("merge-check.sh is back: the checker's levels run the tests") } var found []string err := filepath.WalkDir(root, func(p string, d os.DirEntry, err error) error { if err != nil { return err } if d.IsDir() && (d.Name() == "node_modules" || d.Name() == ".git") { return filepath.SkipDir } if !d.IsDir() && d.Name() == "module.json" { found = append(found, filepath.ToSlash(p)) } return nil }) if err != nil { t.Fatal(err) } if len(found) != 1 || !strings.HasSuffix(found[0], "/node-tools/module.json") { t.Errorf("the module manifests are %v, want node-tools' alone", found) } }