banger/internal/paths/paths_test.go
Thales Maciel 572bf32424
Remove runtime-bundle image dependencies
Hard-cut banger away from source-checkout runtime bundles as an implicit source of\nimage and host defaults. Managed images now own their full boot set,\nimage build starts from an existing registered image, and daemon startup\nno longer synthesizes a default image from host paths.\n\nResolve Firecracker from PATH or firecracker_bin, make SSH keys config-owned\nwith an auto-managed XDG default, replace the external name generator and\npackage manifests with Go code, and keep the vsock helper as a companion\nbinary instead of a user-managed runtime asset.\n\nUpdate the manual scripts, web/CLI forms, config surface, and docs around\nthe new build/manual flow and explicit image registration semantics.\n\nValidation: GOCACHE=/tmp/banger-gocache go test ./..., bash -n scripts/*.sh,\nand make build.
2026-03-21 18:34:53 -03:00

70 lines
1.8 KiB
Go

package paths
import (
"os"
"path/filepath"
"testing"
)
func TestCompanionBinaryPathPrefersEnv(t *testing.T) {
t.Setenv("BANGER_VSOCK_AGENT_BIN", "/tmp/custom-vsock-agent")
got, err := CompanionBinaryPath("banger-vsock-agent")
if err != nil {
t.Fatalf("CompanionBinaryPath: %v", err)
}
if got != "/tmp/custom-vsock-agent" {
t.Fatalf("CompanionBinaryPath() = %q", got)
}
}
func TestCompanionBinaryPathUsesSiblingBinary(t *testing.T) {
root := t.TempDir()
companion := filepath.Join(root, "banger-vsock-agent")
if err := os.WriteFile(companion, []byte("test"), 0o755); err != nil {
t.Fatalf("write companion: %v", err)
}
origExecutablePath := executablePath
executablePath = func() (string, error) {
return filepath.Join(root, "banger"), nil
}
t.Cleanup(func() {
executablePath = origExecutablePath
})
got, err := CompanionBinaryPath("banger-vsock-agent")
if err != nil {
t.Fatalf("CompanionBinaryPath: %v", err)
}
if got != companion {
t.Fatalf("CompanionBinaryPath() = %q, want %q", got, companion)
}
}
func TestCompanionBinaryPathUsesInstalledLibDir(t *testing.T) {
root := t.TempDir()
companion := filepath.Join(root, "lib", "banger", "banger-vsock-agent")
if err := os.MkdirAll(filepath.Dir(companion), 0o755); err != nil {
t.Fatalf("mkdir companion dir: %v", err)
}
if err := os.WriteFile(companion, []byte("test"), 0o755); err != nil {
t.Fatalf("write companion: %v", err)
}
origExecutablePath := executablePath
executablePath = func() (string, error) {
return filepath.Join(root, "bin", "banger"), nil
}
t.Cleanup(func() {
executablePath = origExecutablePath
})
got, err := CompanionBinaryPath("banger-vsock-agent")
if err != nil {
t.Fatalf("CompanionBinaryPath: %v", err)
}
if got != companion {
t.Fatalf("CompanionBinaryPath() = %q, want %q", got, companion)
}
}