Files
ClaudeandClaude Opus 5 4909edee2d Deployr 0.1.0: cross-platform application deployment CLI
Replaces Ninite for endpoint software: one catalog, one command line, and the
same behaviour on Windows, macOS and Linux. Single static binary, no server and
no agent, driven from an RMM script runner or by hand.

- catalog of ~50 apps compiled into the binary, extendable with YAML overlays
  in catalog.d or via --catalog, no rebuild required
- providers: winget, choco, brew, cask, apt, dnf/yum, zypper, pacman, flatpak,
  snap, plus direct vendor downloads (msi/exe/msu/dmg/pkg/deb/rpm/zip/tar.gz/
  AppImage)
- sources are tried in order and fall through, so one catalog entry covers
  winget on Windows, a cask on macOS and the vendor .deb on Debian
- provider-independent detection (registry, paths, commands) makes runs
  idempotent even for software installed by hand
- unattended by construction: stdin closed, silent flags, per-command timeouts
- handles the traps that break naive wrappers: winget missing under SYSTEM,
  Homebrew refusing root, 1641/3010 reboot exits, "already installed" reported
  as failure
- --json summary on stdout with progress on stderr, and RMM-friendly exit codes
  (0 ok, 1 failed, 2 usage, 3 privileges)

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-26 16:55:13 -05:00

99 lines
2.6 KiB
Go

package platform
import (
"os"
"path/filepath"
"runtime"
"strings"
"testing"
)
func TestExpandPathWindowsStyleVariables(t *testing.T) {
t.Setenv("DEPLOYR_TEST_DIR", filepath.Join("C:", "Apps"))
got := ExpandPath("%DEPLOYR_TEST_DIR%/tool/bin.exe")
want := filepath.Clean(filepath.Join("C:", "Apps", "tool", "bin.exe"))
if got != want {
t.Errorf("ExpandPath = %q, want %q", got, want)
}
}
func TestExpandPathUnixStyleVariables(t *testing.T) {
t.Setenv("DEPLOYR_TEST_DIR", filepath.Join("/opt", "apps"))
got := ExpandPath("$DEPLOYR_TEST_DIR/tool")
want := filepath.Clean(filepath.Join("/opt", "apps", "tool"))
if got != want {
t.Errorf("ExpandPath = %q, want %q", got, want)
}
}
// Variable names with parentheses are common on Windows -- %ProgramFiles(x86)%
// is the one that matters -- so the expander has to accept them.
func TestExpandPathHandlesParenthesisedVariables(t *testing.T) {
t.Setenv("DEPLOYR_TEST(x86)", "/legacy")
got := ExpandPath("%DEPLOYR_TEST(x86)%/app")
if !strings.Contains(got, "legacy") {
t.Errorf("ExpandPath = %q, want it to contain the expanded value", got)
}
}
func TestExpandPathTilde(t *testing.T) {
home, err := os.UserHomeDir()
if err != nil {
t.Skip("no home directory in this environment")
}
if got := ExpandPath("~/deployr"); got != filepath.Clean(filepath.Join(home, "deployr")) {
t.Errorf("ExpandPath = %q", got)
}
}
func TestExpandPathEmpty(t *testing.T) {
if got := ExpandPath(""); got != "" {
t.Errorf("ExpandPath(\"\") = %q, want an empty string", got)
}
}
func TestPathExists(t *testing.T) {
dir := t.TempDir()
file := filepath.Join(dir, "present.txt")
if err := os.WriteFile(file, []byte("x"), 0o644); err != nil {
t.Fatal(err)
}
if !PathExists(file) {
t.Error("an existing file should be detected")
}
if PathExists(filepath.Join(dir, "absent.txt")) {
t.Error("a missing file should not be detected")
}
if !PathExists(filepath.Join(dir, "*.txt")) {
t.Error("a glob matching a file should be detected")
}
if PathExists(filepath.Join(dir, "*.log")) {
t.Error("a glob matching nothing should not be detected")
}
if PathExists("") {
t.Error("an empty path should not be detected")
}
}
func TestDirectoriesAreAbsolute(t *testing.T) {
for name, dir := range map[string]string{
"data": DataDir(),
"logs": LogDir(),
"cache": CacheDir(),
} {
if !filepath.IsAbs(dir) {
t.Errorf("%s dir %q is not absolute", name, dir)
}
}
if len(CatalogDirs()) == 0 {
t.Error("there should be at least one catalog overlay directory")
}
}
func TestSupported(t *testing.T) {
if !Supported() {
t.Errorf("%s should be a supported platform", runtime.GOOS)
}
}