package builder import ( "testing" "github.com/novox/mesh-controller/internal/catalogue" ) // The name a machine runs a binary by is not always the name of the package that built it. The host's // command is cmd/mesh-host and every machine runs it as nox-mesh-host — the path it is installed at, // the name in its unit, and the name its launcher looks for inside a delivered version. // // A bundle carrying the package's name was delivered to a machine correctly, reported "created … 1 // file(s)", and was invisible to the launcher (novox/hq 04-ISSUES/142). Found by reading the delivered // directory rather than by trusting the line that said it worked. func TestACompiledArtifactNamesTheBinaryAMachineWillRun(t *testing.T) { got := binaryName(catalogue.Artifact{ Name: "host-arch", From: "cmd/mesh-host", Binary: "nox-mesh-host", }) if got != "nox-mesh-host" { t.Fatalf("the binary is named %q, and the launcher looks for nox-mesh-host", got) } } func TestSayingNothingKeepsWhatTheCompilerWouldHaveChosen(t *testing.T) { // go build names its output after the package, so an artifact that says nothing gets the same // thing it got before this existed. if got := binaryName(catalogue.Artifact{Name: "host-arch", From: "cmd/mesh-host"}); got != "mesh-host" { t.Fatalf("an artifact naming no binary produced %q", got) } if got := binaryName(catalogue.Artifact{Name: "host-arch", From: "./cmd/agent/"}); got != "agent" { t.Fatalf("a from with slashes produced %q", got) } } func TestABundleBuiltFromTheModuleRootFallsBackToItsArtifactName(t *testing.T) { // A single-command repository names no package, and `go build -o ` would then write a file // named after the module directory — which is not something the manifest states. The artifact's // own name is what the manifest does state. if got := binaryName(catalogue.Artifact{Name: "tool"}); got != "tool" { t.Fatalf("a bundle built from the root produced %q", got) } }