Initial commit: Go driver for the Lian Li Galahad II LCD
Streams H.264 to the Galahad II LCD via USB (gousb) with: - ffmpeg CLI transcoding (no fragile FFmpeg C-ABI bindings) - pure-Go Annex-B access-unit splitting - framerate pacing with graceful shutdown and USB reconnect - TOML config, cobra CLI, structured slog logging, unit tests
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDefault(t *testing.T) {
|
||||
cfg := Default()
|
||||
if cfg.Display.Speed != 1.0 {
|
||||
t.Errorf("default speed = %v, want 1.0", cfg.Display.Speed)
|
||||
}
|
||||
if cfg.USB.VendorID != DefaultVendorID || cfg.USB.ProductID != DefaultProductID {
|
||||
t.Errorf("default usb ids = %x:%x, want %x:%x",
|
||||
cfg.USB.VendorID, cfg.USB.ProductID, DefaultVendorID, DefaultProductID)
|
||||
}
|
||||
if cfg.Stream.CachePath == "" {
|
||||
t.Error("default cache_path must not be empty")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadMissingFileReturnsDefaults(t *testing.T) {
|
||||
cfg, err := Load(filepath.Join(t.TempDir(), "nope.toml"))
|
||||
if err != nil {
|
||||
t.Fatalf("Load(missing) error = %v", err)
|
||||
}
|
||||
if cfg.Display.Input != "" {
|
||||
t.Errorf("input = %q, want empty", cfg.Display.Input)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSaveAndLoadRoundTrip(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "sub", "galahad2lcd.toml")
|
||||
orig := Default()
|
||||
orig.Display.Input = "/tmp/demo.gif"
|
||||
orig.Display.Rotate = 180
|
||||
orig.Display.Speed = 1.5
|
||||
orig.USB.VendorID = 0x1234
|
||||
orig.Stream.FPS = 15
|
||||
|
||||
if err := orig.Save(path); err != nil {
|
||||
t.Fatalf("Save error = %v", err)
|
||||
}
|
||||
|
||||
got, err := Load(path)
|
||||
if err != nil {
|
||||
t.Fatalf("Load error = %v", err)
|
||||
}
|
||||
if got.Display != orig.Display {
|
||||
t.Errorf("display = %+v, want %+v", got.Display, orig.Display)
|
||||
}
|
||||
if got.USB != orig.USB {
|
||||
t.Errorf("usb = %+v, want %+v", got.USB, orig.USB)
|
||||
}
|
||||
if got.Stream != orig.Stream {
|
||||
t.Errorf("stream = %+v, want %+v", got.Stream, orig.Stream)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidate(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
mutate func(*Config)
|
||||
wantErr bool
|
||||
}{
|
||||
{"valid", func(c *Config) { c.Display.Input = "/tmp/x.gif" }, false},
|
||||
{"empty input", func(c *Config) {}, true},
|
||||
{"bad rotate", func(c *Config) { c.Display.Input = "/tmp/x.gif"; c.Display.Rotate = 45 }, true},
|
||||
{"negative speed", func(c *Config) { c.Display.Input = "/tmp/x.gif"; c.Display.Speed = -1 }, true},
|
||||
{"negative fps", func(c *Config) { c.Display.Input = "/tmp/x.gif"; c.Stream.FPS = -2 }, true},
|
||||
{"empty cache", func(c *Config) { c.Display.Input = "/tmp/x.gif"; c.Stream.CachePath = "" }, true},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cfg := Default()
|
||||
tt.mutate(&cfg)
|
||||
err := cfg.Validate()
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("Validate() error = %v, wantErr = %v", err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user