Move the capture/encode/send pipeline out of cmd/teleportfling into a GUI-free Engine so the CLI and the desktop app share one implementation: - flinger: Config/Engine/Status, audio+video+stats loops, pattern source - config: JSON persistence at ~/.config/teleportfling/config.json - cmd/teleportfling: thin CLI wrapper around the engine (same flags) - golangci: extend exclusions to flinger/config
78 lines
1.7 KiB
Go
78 lines
1.7 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
// TestLoadDefaultsWhenMissing verifies Load returns defaults when the file
|
|
// does not exist.
|
|
func TestLoadDefaultsWhenMissing(t *testing.T) {
|
|
// Point at a non-existent directory so we never touch the real config.
|
|
old := pathVar
|
|
pathVar = filepath.Join(t.TempDir(), "nope", "config.json")
|
|
defer func() { pathVar = old }()
|
|
|
|
c, err := Load()
|
|
if err != nil {
|
|
t.Fatalf("Load: %v", err)
|
|
}
|
|
if c.Port != 9756 {
|
|
t.Errorf("default port = %d, want 9756", c.Port)
|
|
}
|
|
}
|
|
|
|
// TestSaveLoadRoundTrip writes a config and reads it back.
|
|
func TestSaveLoadRoundTrip(t *testing.T) {
|
|
old := pathVar
|
|
pathVar = filepath.Join(t.TempDir(), "config.json")
|
|
defer func() { pathVar = old }()
|
|
|
|
want := Config{
|
|
Name: "Studio",
|
|
Port: 9898,
|
|
Quality: 95,
|
|
FPS: 60,
|
|
Source: "pattern",
|
|
Audio: false,
|
|
StreamIndex: 1,
|
|
}
|
|
if err := Save(want); err != nil {
|
|
t.Fatalf("Save: %v", err)
|
|
}
|
|
|
|
got, err := Load()
|
|
if err != nil {
|
|
t.Fatalf("Load: %v", err)
|
|
}
|
|
if got != want {
|
|
t.Errorf("round trip mismatch:\n got %+v\nwant %+v", got, want)
|
|
}
|
|
}
|
|
|
|
// TestLoadFillsZeroValues ensures a partial file gets defaults filled.
|
|
func TestLoadFillsZeroValues(t *testing.T) {
|
|
old := pathVar
|
|
pathVar = filepath.Join(t.TempDir(), "config.json")
|
|
defer func() { pathVar = old }()
|
|
|
|
if err := os.WriteFile(pathVar, []byte(`{"name":"Partial"}`), 0o600); err != nil {
|
|
t.Fatalf("write: %v", err)
|
|
}
|
|
|
|
c, err := Load()
|
|
if err != nil {
|
|
t.Fatalf("Load: %v", err)
|
|
}
|
|
if c.Name != "Partial" {
|
|
t.Errorf("name = %q, want Partial", c.Name)
|
|
}
|
|
if c.Port != 9756 {
|
|
t.Errorf("port = %d, want filled default 9756", c.Port)
|
|
}
|
|
if c.Quality != 80 {
|
|
t.Errorf("quality = %d, want filled default 80", c.Quality)
|
|
}
|
|
}
|