Fix the misleading make install path where banger and bangerd still depended on a repo checkout for Firecracker, guest artifacts, image builds, and the SSH key. Replace repo-root inference with an explicit runtime bundle model: resolve a runtime_dir from env/config/install layout, derive concrete artifact paths from it, and update the daemon, CLI, and image-build flow to use those paths. Keep repo_root only as an explicit compatibility alias instead of auto-detecting it. Teach customize.sh to run from a read-only bundled runtime tree while writing transient state under XDG/BANGER_STATE_DIR, and make make install copy the runtime assets into PREFIX/lib/banger so installed binaries stay usable outside the repo. Validate with go test ./..., make build, bash -n customize.sh, and make install DESTDIR=/tmp/banger-install PREFIX=/usr. An out-of-repo installed-binary smoke test was attempted, but this sandbox blocked bangerd from binding its Unix socket (setsockopt: operation not permitted).
69 lines
1.7 KiB
Go
69 lines
1.7 KiB
Go
package paths
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestResolveRuntimeDirPrefersEnv(t *testing.T) {
|
|
t.Setenv("BANGER_RUNTIME_DIR", "/env/runtime")
|
|
|
|
if got := ResolveRuntimeDir("/config/runtime", "/deprecated/repo"); got != "/env/runtime" {
|
|
t.Fatalf("ResolveRuntimeDir() = %q, want /env/runtime", got)
|
|
}
|
|
}
|
|
|
|
func TestResolveRuntimeDirUsesInstalledLayout(t *testing.T) {
|
|
root := t.TempDir()
|
|
runtimeDir := filepath.Join(root, "lib", "banger")
|
|
createRuntimeBundle(t, runtimeDir)
|
|
|
|
origExecutablePath := executablePath
|
|
executablePath = func() (string, error) {
|
|
return filepath.Join(root, "bin", "banger"), nil
|
|
}
|
|
t.Cleanup(func() {
|
|
executablePath = origExecutablePath
|
|
})
|
|
|
|
if got := ResolveRuntimeDir("", ""); got != runtimeDir {
|
|
t.Fatalf("ResolveRuntimeDir() = %q, want %q", got, runtimeDir)
|
|
}
|
|
}
|
|
|
|
func TestResolveRuntimeDirUsesExecutableDirectoryBundle(t *testing.T) {
|
|
root := t.TempDir()
|
|
createRuntimeBundle(t, root)
|
|
|
|
origExecutablePath := executablePath
|
|
executablePath = func() (string, error) {
|
|
return filepath.Join(root, "banger"), nil
|
|
}
|
|
t.Cleanup(func() {
|
|
executablePath = origExecutablePath
|
|
})
|
|
|
|
if got := ResolveRuntimeDir("", ""); got != root {
|
|
t.Fatalf("ResolveRuntimeDir() = %q, want %q", got, root)
|
|
}
|
|
}
|
|
|
|
func createRuntimeBundle(t *testing.T, runtimeDir string) {
|
|
t.Helper()
|
|
for _, rel := range []string{
|
|
"firecracker",
|
|
"customize.sh",
|
|
"packages.apt",
|
|
"rootfs-docker.ext4",
|
|
"wtf/root/boot/vmlinux-6.8.0-94-generic",
|
|
} {
|
|
path := filepath.Join(runtimeDir, rel)
|
|
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
|
t.Fatalf("mkdir %s: %v", filepath.Dir(path), err)
|
|
}
|
|
if err := os.WriteFile(path, []byte("test"), 0o644); err != nil {
|
|
t.Fatalf("write %s: %v", path, err)
|
|
}
|
|
}
|
|
}
|