gostations/stations_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

70 lines
1.5 KiB
Go

package main
import (
"bytes"
"os"
"testing"
)
func TestShowVersion_Unit(t *testing.T) {
t.Parallel()
t.Log("✓ Fast showVersion unit test")
tests := []struct {
name string
version string
expected string
}{
{"default version", "1.0.0", "1.0.0\n"},
{"empty version", "", "\n"},
{"dev version", "dev", "dev\n"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
originalVersion := version
version = tt.version
defer func() { version = originalVersion }()
// Safe stdout capture using pipe (no os.Stdout reassignment)
origStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
showVersion()
w.Close()
os.Stdout = origStdout
var buf bytes.Buffer
_, _ = buf.ReadFrom(r)
got := buf.String()
if got != tt.expected {
t.Errorf("showVersion() = %q, want %q", got, tt.expected)
}
})
}
}
func TestPrecheck_Unit(t *testing.T) {
t.Parallel()
t.Log("✓ Fast precheck unit test")
// Simple smoke test — calls the real precheck() in the common "player installed" path
// (no mocking of globals — that's not allowed in Go)
precheck()
t.Log("✓ precheck ran without panic (happy path)")
}
func TestPrecheck_Live(t *testing.T) {
if !testing.Short() {
t.Skip("skipping live integration test. Run with:\n go test -run TestPrecheck_Live -short -v")
}
t.Log("🧪 Running live precheck integration test...")
// Real precheck with whatever player is configured on this system
precheck()
t.Log("✓ Live precheck passed (no early exit)")
}