novox/hq ADR 0142, which decided this and was not implemented: "It is unpacked into a directory named for its version, so it can read its own version from its path. The stamp goes, and with it the need for a build to know what it will be called." The mesh's toolchain stamps no version, on purpose, so a delivered host called itself "development build" and the mesh could not tell which host any machine ran — which is the whole of what 087 added. A delivered host lives at <libexec>/versions/<version>/<binary>, and that directory is the answer. A host placed by hand keeps its stamp, which is the honest answer for one the mesh did not deliver, and is every machine until a delivery reaches it. A binary sitting anywhere else is not read as a version at all. The decision is split from the reading so a test can ask about a path without being that binary.
49 lines
1.7 KiB
Go
49 lines
1.7 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)
|
|
}
|
|
}
|
|
}
|