The node-engine held 1,707 top-level unit tests against the budget of 500 a module. Each unit test file with two or more tests now runs them as subtests of one test named for the file, each named as its function was, in the same order: every check is kept, and the check counts 383. Files with a TestMain, a re-run of a test by its name, or the integration tag are left. Four files of this branch's earlier commits are formatted. Builds: design 47 H2 §819; H-A-349 DQ-14
108 lines
4.0 KiB
Go
108 lines
4.0 KiB
Go
// Package examples checks the bundles shipped in this directory.
|
|
//
|
|
// **Nothing checked them before.** `foundation-first-node.lock` is what a machine becomes when
|
|
// there is no mesh to ask — the one declaration applied with nothing to verify it against — and
|
|
// it was edited by hand and read by nobody but a running host.
|
|
package examples
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"sort"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/declaration"
|
|
)
|
|
|
|
func bundle(t *testing.T) *declaration.Declaration {
|
|
t.Helper()
|
|
raw, err := os.ReadFile("foundation-first-node.lock")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
d, err := declaration.ParseFileTrusted(raw)
|
|
if err != nil {
|
|
t.Fatalf("the bundle a first node applies does not parse: %v", err)
|
|
}
|
|
return d
|
|
}
|
|
|
|
// Defends novox/hq ADR 0028: the foundation supplies the control plane and nothing else.
|
|
//
|
|
// The object store was foundation for months on the strength of "it cannot grant itself a bucket",
|
|
// which answers half the test. The control plane never needed one, and nothing noticed because
|
|
// nothing counted what the bundle holds.
|
|
func testTheBundleCarriesTheFoundationAndTheControlPlaneAndNothingElse(t *testing.T) {
|
|
var images []string
|
|
for _, r := range bundle(t).Resources {
|
|
c, ok := r.(*declaration.Container)
|
|
if !ok {
|
|
continue
|
|
}
|
|
// The registry the images come from is the lab's, and is not what this asserts.
|
|
name := c.Image
|
|
if i := strings.LastIndex(name, "/"); i >= 0 {
|
|
name = name[i+1:]
|
|
}
|
|
images = append(images, strings.SplitN(name, "@", 2)[0])
|
|
}
|
|
sort.Strings(images)
|
|
|
|
want := []string{"mesh-controller", "nats", "pgvector"}
|
|
if strings.Join(images, ",") != strings.Join(want, ",") {
|
|
t.Fatalf("the bundle carries %v; expected exactly %v.\n\n"+
|
|
"Adding one is a change to what every first node becomes, and to ADR 0006's "+
|
|
"membership — take it deliberately, not by editing a lock file.", images, want)
|
|
}
|
|
}
|
|
|
|
// The control plane is in the bundle, and the design overlooked it once by reasoning about
|
|
// foundation services rather than counting containers (novox/hq 03-DESIGN/01-to-be/07).
|
|
func testTheControlPlaneIsCarriedToo(t *testing.T) {
|
|
for _, r := range bundle(t).Resources {
|
|
if c, ok := r.(*declaration.Container); ok && strings.Contains(c.Image, "mesh-controller") {
|
|
return
|
|
}
|
|
}
|
|
t.Fatal("nothing in the bundle starts the control plane, so the machine would raise a " +
|
|
"foundation and stop")
|
|
}
|
|
|
|
// One genesis bundle, on the bus the mesh runs on (novox/hq ADR 0331 §2). Two bundles let every bed
|
|
// and README name the one that could not raise a mesh, for weeks (issue 146).
|
|
func testThereIsOneGenesisBundle(t *testing.T) {
|
|
bundles, err := filepath.Glob("*.lock")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(bundles) != 1 || bundles[0] != "foundation-first-node.lock" {
|
|
t.Fatalf("examples/ holds %v; it holds one genesis bundle, foundation-first-node.lock", bundles)
|
|
}
|
|
}
|
|
|
|
// The control plane the bundle raises is given the bus, with the account the installer fills and
|
|
// the certificate it pins (ADR 0331 §4); without it, it crash-loops for ever (issue 146).
|
|
func testTheControlPlaneIsGivenTheBus(t *testing.T) {
|
|
for _, r := range bundle(t).Resources {
|
|
c, ok := r.(*declaration.Container)
|
|
if !ok || !strings.Contains(c.Image, "mesh-controller") {
|
|
continue
|
|
}
|
|
if !strings.HasPrefix(c.Env["MESH_BUS_NATS"], "nats://controller:bootstrap@") || c.Env["MESH_BROKER_CERTIFICATE"] == "" {
|
|
t.Fatalf("the control plane is given the bus %q and the certificate %q",
|
|
c.Env["MESH_BUS_NATS"], c.Env["MESH_BROKER_CERTIFICATE"])
|
|
}
|
|
return
|
|
}
|
|
t.Fatal("nothing in the bundle starts the control plane")
|
|
}
|
|
|
|
// TestBundle runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
|
func TestBundle(t *testing.T) {
|
|
t.Run("TheBundleCarriesTheFoundationAndTheControlPlaneAndNothingElse", testTheBundleCarriesTheFoundationAndTheControlPlaneAndNothingElse)
|
|
t.Run("TheControlPlaneIsCarriedToo", testTheControlPlaneIsCarriedToo)
|
|
t.Run("ThereIsOneGenesisBundle", testThereIsOneGenesisBundle)
|
|
t.Run("TheControlPlaneIsGivenTheBus", testTheControlPlaneIsGivenTheBus)
|
|
}
|