gostations/commander_test.go
Greg Gauthier 5bbeb66afb
All checks were successful
gobuild / build (push) Successful in 21s
test: add unit and integration tests for core functionality
Added comprehensive unit and live integration tests in new files:
- commander_test.go: Covers isInstalled and subExecute functions
- filer_test.go: Covers createIniFile with various scenarios
- radiomenu_test.go: Covers Short, Quit, and RadioMenu
- stations_test.go: Covers showVersion and precheck

These tests ensure reliability across happy paths, edge cases, and live environments.
2026-03-03 19:21:24 +00:00

72 lines
1.6 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. Run with:\n go test -run TestSubExecute_Live -short -v")
}
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")
}