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
56 lines
2.1 KiB
Go
56 lines
2.1 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
// A component's version comes from where it sits, not from its linker (novox/hq ADR 0142). The mesh's
|
|
// toolchain stamps no version — a build does not know what it will be called — so a delivered host
|
|
// read as "development build" and the mesh could not tell which host a machine ran (04-ISSUES/161).
|
|
|
|
func testADeliveredHostReadsItsVersionFromItsPath(t *testing.T) {
|
|
// A delivered host lives at <libexec>/versions/<version>/<binary>.
|
|
dir := t.TempDir()
|
|
versioned := filepath.Join(dir, "versions", "637f65559d16")
|
|
if err := os.MkdirAll(versioned, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
self := filepath.Join(versioned, "nox-mesh-host")
|
|
if err := os.WriteFile(self, []byte("#!/bin/sh\n"), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := versionAt(self, "development build"); got != "637f65559d16" {
|
|
t.Fatalf("a delivered host read its version as %q", got)
|
|
}
|
|
}
|
|
|
|
func testAHostPlacedByHandKeepsItsStamp(t *testing.T) {
|
|
// The honest answer for one the mesh did not deliver — and every machine is in that state until
|
|
// a delivery reaches it.
|
|
if got := versionAt("/usr/bin/nox-mesh-host", "04a27ca"); got != "04a27ca" {
|
|
t.Fatalf("a hand-placed host read its version as %q", got)
|
|
}
|
|
}
|
|
|
|
func testADirectoryThatIsNotAVersionIsNotReadAsOne(t *testing.T) {
|
|
// A binary sitting anywhere else must not have its parent directory's name read as a version.
|
|
for _, path := range []string{
|
|
"/opt/somewhere/nox-mesh-host",
|
|
"/usr/lib/nox-mesh-host/launch",
|
|
"/home/someone/build/nox-mesh-host",
|
|
} {
|
|
if got := versionAt(path, "the stamp"); got != "the stamp" {
|
|
t.Fatalf("%s read its version as %q", path, got)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestVersionFromPath runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
|
func TestVersionFromPath(t *testing.T) {
|
|
t.Run("ADeliveredHostReadsItsVersionFromItsPath", testADeliveredHostReadsItsVersionFromItsPath)
|
|
t.Run("AHostPlacedByHandKeepsItsStamp", testAHostPlacedByHandKeepsItsStamp)
|
|
t.Run("ADirectoryThatIsNotAVersionIsNotReadAsOne", testADirectoryThatIsNotAVersionIsNotReadAsOne)
|
|
}
|