CI / Lint (push) Successful in 18m7s
CI / Test (push) Successful in 9m2s
CI / Build (darwin/amd64) (push) Failing after 4m4s
CI / Build (linux/amd64) (push) Failing after 4m7s
CI / Build (windows/amd64) (push) Failing after 4m5s
CI / Build (darwin/arm64) (push) Failing after 4m4s
CI / Build (linux/arm64) (push) Failing after 4m7s
CI / Build (windows/arm64) (push) Failing after 4m6s
CI / Release (push) Skipped
- clipboard_windows.go: remplacement unsafe.Pointer par unsafe.Add pour go vet 1.26 - clipboard_windows.go: correction errcheck (defer syscall) et ineffassign - daemon_test.go: mockClipboard thread-safe avec sync.RWMutex (data race) - daemon_test.go: correction errcheck sur go da.Run() - server_test.go: vérification des erreurs json.Marshal - config_test.go: vérification des erreurs MkdirAll/WriteFile - peers.example.toml: mise à jour au format TOML actuel
128 lines
2.9 KiB
Go
128 lines
2.9 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestLoadDefaults(t *testing.T) {
|
|
// Point HOME/USERPROFILE to a temp dir with no config file.
|
|
tmp := t.TempDir()
|
|
t.Setenv("HOME", tmp)
|
|
t.Setenv("USERPROFILE", tmp) // Windows compatibility
|
|
|
|
cfg, err := Load()
|
|
if err != nil {
|
|
t.Fatalf("Load() error: %v", err)
|
|
}
|
|
|
|
if cfg.Daemon.Port != DefaultPort {
|
|
t.Errorf("default port = %d, want %d", cfg.Daemon.Port, DefaultPort)
|
|
}
|
|
if cfg.Daemon.PollIntervalMs != DefaultPollIntervalMs {
|
|
t.Errorf("default poll = %d, want %d", cfg.Daemon.PollIntervalMs, DefaultPollIntervalMs)
|
|
}
|
|
if len(cfg.Peers) != 0 {
|
|
t.Errorf("default peers = %d, want 0", len(cfg.Peers))
|
|
}
|
|
}
|
|
|
|
func TestLoadFromFile(t *testing.T) {
|
|
tmp := t.TempDir()
|
|
cfgDir := filepath.Join(tmp, ConfigDir)
|
|
if err := os.MkdirAll(cfgDir, 0755); err != nil {
|
|
t.Fatalf("MkdirAll: %v", err)
|
|
}
|
|
|
|
content := `
|
|
[daemon]
|
|
port = 9999
|
|
poll_interval_ms = 250
|
|
|
|
[[peers]]
|
|
name = "bureau"
|
|
addr = "192.168.1.10:9137"
|
|
|
|
[[peers]]
|
|
name = "portable"
|
|
addr = "192.168.1.20:9137"
|
|
`
|
|
if err := os.WriteFile(filepath.Join(cfgDir, ConfigFile), []byte(content), 0644); err != nil {
|
|
t.Fatalf("WriteFile: %v", err)
|
|
}
|
|
t.Setenv("HOME", tmp)
|
|
t.Setenv("USERPROFILE", tmp) // Windows compatibility
|
|
|
|
cfg, err := Load()
|
|
if err != nil {
|
|
t.Fatalf("Load() error: %v", err)
|
|
}
|
|
|
|
if cfg.Daemon.Port != 9999 {
|
|
t.Errorf("port = %d, want 9999", cfg.Daemon.Port)
|
|
}
|
|
if cfg.Daemon.PollIntervalMs != 250 {
|
|
t.Errorf("poll = %d, want 250", cfg.Daemon.PollIntervalMs)
|
|
}
|
|
if len(cfg.Peers) != 2 {
|
|
t.Fatalf("peers = %d, want 2", len(cfg.Peers))
|
|
}
|
|
if cfg.Peers[0].Name != "bureau" {
|
|
t.Errorf("peer[0].Name = %q, want \"bureau\"", cfg.Peers[0].Name)
|
|
}
|
|
if cfg.Peers[1].Addr != "192.168.1.20:9137" {
|
|
t.Errorf("peer[1].Addr = %q", cfg.Peers[1].Addr)
|
|
}
|
|
}
|
|
|
|
func TestEnvOverride(t *testing.T) {
|
|
tmp := t.TempDir()
|
|
t.Setenv("HOME", tmp)
|
|
t.Setenv("USERPROFILE", tmp) // Windows compatibility
|
|
t.Setenv("CLIP_SYNC_PORT", "8080")
|
|
t.Setenv("CLIP_SYNC_POLL_MS", "100")
|
|
|
|
cfg, err := Load()
|
|
if err != nil {
|
|
t.Fatalf("Load() error: %v", err)
|
|
}
|
|
|
|
if cfg.Daemon.Port != 8080 {
|
|
t.Errorf("port = %d, want 8080", cfg.Daemon.Port)
|
|
}
|
|
if cfg.Daemon.PollIntervalMs != 100 {
|
|
t.Errorf("poll = %d, want 100", cfg.Daemon.PollIntervalMs)
|
|
}
|
|
}
|
|
|
|
func TestEnvOverrideInvalidPort(t *testing.T) {
|
|
tmp := t.TempDir()
|
|
t.Setenv("HOME", tmp)
|
|
t.Setenv("USERPROFILE", tmp) // Windows compatibility
|
|
t.Setenv("CLIP_SYNC_PORT", "not-a-number")
|
|
|
|
_, err := Load()
|
|
if err == nil {
|
|
t.Fatal("expected error for invalid CLIP_SYNC_PORT, got nil")
|
|
}
|
|
}
|
|
|
|
func TestPollInterval(t *testing.T) {
|
|
cfg := &Config{
|
|
Daemon: DaemonConfig{PollIntervalMs: 500},
|
|
}
|
|
if d := cfg.PollInterval(); d.Milliseconds() != 500 {
|
|
t.Errorf("PollInterval = %v, want 500ms", d)
|
|
}
|
|
}
|
|
|
|
func TestListenAddr(t *testing.T) {
|
|
cfg := &Config{
|
|
Daemon: DaemonConfig{Port: 9137},
|
|
}
|
|
if addr := cfg.ListenAddr(); addr != ":9137" {
|
|
t.Errorf("ListenAddr = %q, want \":9137\"", addr)
|
|
}
|
|
}
|