gostations/commander_test.go
Greg Gauthier b378fec3b2
Some checks failed
gobuild / build (push) Failing after 4s
refactor: reorganize into internal packages, fix critical panics and error handling
Move browser, config, player, and radio logic into internal/{config,radio,player,ui,version}.
Add cached API host resolution, context-aware HTTP client, and nil/length guards to eliminate
RandomIP, nslookup, reverseLookup, and GetStations panics. Replace subExecute with clean
legacyPlayer using Run-only execution. Fix inverted -short test guards, unformatted config
error messages, and "Erorr" typo. Remove obsolete vendor/GOPATH logic from build scripts.
Update callers in stations.go and radiomenu.go to new paths; retain shims for transition.
2026-06-05 21:10:54 +01:00

72 lines
1.5 KiB
Go

package main
import (
"runtime"
"testing"
)
func TestIsInstalled_Unit(t *testing.T) {
t.Parallel()
t.Log("✓ Fast isInstalled unit test")
tests := []struct {
name string
cmd string
want bool
}{
{"sh exists", "sh", true},
{"non-existent", "nonexistentcmd123456789", false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := isInstalled(tt.cmd)
if got != tt.want {
t.Errorf("isInstalled(%q) = %v, want %v", tt.cmd, got, tt.want)
}
})
}
}
func TestIsInstalled_Live(t *testing.T) {
if !testing.Short() {
t.Skip("skipping live integration test. Run with:\n go test -run TestIsInstalled_Live -short -v")
}
t.Log("🧪 Running live isInstalled integration test...")
if runtime.GOOS == "windows" {
t.Skip("isInstalled uses /bin/sh (Unix-only)")
}
if !isInstalled("sh") {
t.Error("sh should be installed on this system")
}
t.Log("✓ Live isInstalled test passed")
}
func TestSubExecute_Unit(t *testing.T) {
t.Parallel()
t.Log("✓ Fast subExecute unit test")
_, err := subExecute("nonexistentcmd123456789")
if err == nil {
t.Error("expected error for non-existent command")
}
}
func TestSubExecute_Live(t *testing.T) {
if testing.Short() {
t.Skip("skipping live integration test (use without -short)")
}
t.Log("🧪 Running live subExecute integration test...")
output, err := subExecute("echo", "hello from live test")
if err != nil {
t.Fatalf("subExecute failed: %v", err)
}
if len(output) == 0 {
t.Error("expected output")
}
t.Log("✓ subExecute live test passed")
}