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 /versions//. 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) } } }