Null-DRM-Official/apps/streamd/servecmd/config_test.go
404errordeveloper 8fc7e4c0b8 streamd: serve start/stop/update, streamd.yaml, egress, module panel fixes
- Add streamd serve start|stop|restart|status|update with auto-written streamd.yaml
- Panel modules: STREAMD_MODULES_DIR for describe, YAML channel fallback, textarea value fix
- Per-stream WireGuard/SOCKS egress profiles + Settings UI
- Drop drm-* from release builds; track streamd-bg.sh / streamd-update.sh wrappers
- Docs: streamd-server-setup lifecycle and update flow
2026-10-10 18:05:51 +02:00

101 lines
2.7 KiB
Go

package servecmd
import (
"os"
"path/filepath"
"testing"
)
func TestWriteAndLoadFileConfig(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "streamd.yaml")
keep := 5
cookie := true
fc := FileConfig{
Bind: "0.0.0.0:8083",
Data: ".cache/streamd",
LogLevel: "debug",
LogFile: "streamd.log",
PIDFile: "streamd.pid",
Channel: "beta",
KeepOld: &keep,
CookieSecure: &cookie,
}
if err := writeFileConfig(path, fc); err != nil {
t.Fatal(err)
}
got, err := loadFileConfig(path)
if err != nil {
t.Fatal(err)
}
if got.Bind != "0.0.0.0:8083" || got.Channel != "beta" || got.LogLevel != "debug" {
t.Fatalf("got %+v", got)
}
if got.KeepOld == nil || *got.KeepOld != 5 {
t.Fatalf("keep_old=%v", got.KeepOld)
}
}
func TestMergeRelativePaths(t *testing.T) {
root := t.TempDir()
opt := ServeOptions{InstallRoot: root, Bind: defaultBind, KeepOld: 10}
fc := FileConfig{Data: ".cache/streamd", LogFile: "streamd.log", PIDFile: "streamd.pid", Bind: "0.0.0.0:9"}
mergeFileIntoOptions(&opt, fc)
if opt.Bind != "0.0.0.0:9" {
t.Fatalf("bind=%s", opt.Bind)
}
wantData := filepath.Join(root, ".cache", "streamd")
if opt.Data != wantData {
t.Fatalf("data=%s want %s", opt.Data, wantData)
}
}
func TestEnsureConfigWritesOnce(t *testing.T) {
root := t.TempDir()
// Point InstallRoot via a fake by writing to root/streamd.yaml through ensure
opt := ServeOptions{
InstallRoot: root,
Bind: "0.0.0.0:8083",
Data: filepath.Join(root, ".cache", "streamd"),
LogLevel: "info",
LogFile: filepath.Join(root, "streamd.log"),
PIDFile: filepath.Join(root, "streamd.pid"),
Channel: "stable",
KeepOld: 10,
}
path := filepath.Join(root, configFileName)
if err := writeFileConfig(path, optionsToFileConfig(opt)); err != nil {
t.Fatal(err)
}
// Second ensure should not set WroteConfig when loading existing.
opt2 := baseServeOptions()
opt2.InstallRoot = root
// findConfigPath uses real installRoot(); test loadFileConfig merge instead.
fc, err := loadFileConfig(path)
if err != nil {
t.Fatal(err)
}
mergeFileIntoOptions(&opt2, fc)
if opt2.Bind != "0.0.0.0:8083" {
t.Fatalf("bind=%s", opt2.Bind)
}
// Existing file must not be clobbered by a second write of defaults.
before, _ := os.ReadFile(path)
_ = writeFileConfig(path, optionsToFileConfig(opt2))
after, _ := os.ReadFile(path)
if len(before) == 0 || len(after) == 0 {
t.Fatal("empty config")
}
}
func TestUpdateURL(t *testing.T) {
u := updateURL(releaseBaseURL, "stable", "streamd-linux-amd64")
want := releaseBaseURL + "/stable/streamd-linux-amd64"
if u != want {
t.Fatalf("%s != %s", u, want)
}
u = updateURL(releaseBaseURL, "v0.2.0", "streamd-linux-arm64")
if u != releaseBaseURL+"/v0.2.0/streamd-linux-arm64" {
t.Fatal(u)
}
}