Dos daemons compartiendo el mismo config.toml corren sobre el mismo agentId/agentHash/streamSecret y corrompen el estado de sync del otro. flock advisory en <configDir>/unarr.lock al arrancar: el 2º start se niega con mensaje claro. El kernel suelta el lock al morir el proceso (incluido SIGKILL) → sin problema de lock obsoleto. Scope = config dir, no máquina: un UNARR_CONFIG_DIR distinto (p.ej. el agente dev) tiene su propio lock y corre en paralelo. No bloquea una 2ª instalación con config separada — solo el cross-talk de config compartida.
61 lines
1.3 KiB
Go
61 lines
1.3 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestDir(t *testing.T) {
|
|
dir := Dir()
|
|
if dir == "" {
|
|
t.Error("Dir() returned empty string")
|
|
}
|
|
if !strings.Contains(dir, "unarr") {
|
|
t.Errorf("Dir() = %q, should contain 'unarr'", dir)
|
|
}
|
|
}
|
|
|
|
func TestFilePath(t *testing.T) {
|
|
path := FilePath()
|
|
if !strings.HasSuffix(path, "config.toml") {
|
|
t.Errorf("FilePath() = %q, should end with config.toml", path)
|
|
}
|
|
}
|
|
|
|
func TestLockPath(t *testing.T) {
|
|
t.Setenv("UNARR_CONFIG_DIR", "/custom/path")
|
|
path := LockPath()
|
|
if path != "/custom/path/unarr.lock" {
|
|
t.Errorf("LockPath() = %q, want /custom/path/unarr.lock", path)
|
|
}
|
|
}
|
|
|
|
func TestDataDir(t *testing.T) {
|
|
dir := DataDir()
|
|
if dir == "" {
|
|
t.Error("DataDir() returned empty string")
|
|
}
|
|
if !strings.Contains(dir, "unarr") {
|
|
t.Errorf("DataDir() = %q, should contain 'unarr'", dir)
|
|
}
|
|
}
|
|
|
|
func TestDirOverrideEnv(t *testing.T) {
|
|
t.Setenv("UNARR_CONFIG_DIR", "/custom/path")
|
|
dir := Dir()
|
|
if dir != "/custom/path" {
|
|
t.Errorf("Dir() with env = %q, want /custom/path", dir)
|
|
}
|
|
}
|
|
|
|
func TestDirXDGOverride(t *testing.T) {
|
|
// Clear the custom env so XDG takes effect
|
|
os.Unsetenv("UNARR_CONFIG_DIR")
|
|
t.Setenv("XDG_CONFIG_HOME", "/xdg/config")
|
|
|
|
dir := Dir()
|
|
if dir != "/xdg/config/unarr" {
|
|
t.Errorf("Dir() with XDG = %q, want /xdg/config/unarr", dir)
|
|
}
|
|
}
|