Reuse a single long-poll HTTP client instead of creating one per Events() call (~every 30s). Make TLS skip-verify configurable via syncthing_insecure_tls. Log previously swallowed config errors. Add unit tests for all monitor trackers, config, and state logic. Add CI workflow (vet, golangci-lint, govulncheck, go test -race). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
69 lines
1.6 KiB
Go
69 lines
1.6 KiB
Go
package monitor
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.davoryn.de/calic/syncwarden/internal/icons"
|
|
)
|
|
|
|
func TestStateFromFolders_Empty(t *testing.T) {
|
|
got := stateFromFolders(nil, false)
|
|
if got != icons.StateIdle {
|
|
t.Errorf("empty folders should be idle, got %d", got)
|
|
}
|
|
}
|
|
|
|
func TestStateFromFolders_Idle(t *testing.T) {
|
|
folders := []FolderInfo{
|
|
{ID: "a", State: "idle"},
|
|
{ID: "b", State: "idle"},
|
|
}
|
|
got := stateFromFolders(folders, false)
|
|
if got != icons.StateIdle {
|
|
t.Errorf("all idle should be StateIdle, got %d", got)
|
|
}
|
|
}
|
|
|
|
func TestStateFromFolders_Syncing(t *testing.T) {
|
|
folders := []FolderInfo{
|
|
{ID: "a", State: "idle"},
|
|
{ID: "b", State: "syncing"},
|
|
}
|
|
got := stateFromFolders(folders, false)
|
|
if got != icons.StateSyncing {
|
|
t.Errorf("syncing folder should produce StateSyncing, got %d", got)
|
|
}
|
|
}
|
|
|
|
func TestStateFromFolders_ScanningIsSyncing(t *testing.T) {
|
|
folders := []FolderInfo{
|
|
{ID: "a", State: "scanning"},
|
|
}
|
|
got := stateFromFolders(folders, false)
|
|
if got != icons.StateSyncing {
|
|
t.Errorf("scanning should map to StateSyncing, got %d", got)
|
|
}
|
|
}
|
|
|
|
func TestStateFromFolders_ErrorOverSyncing(t *testing.T) {
|
|
folders := []FolderInfo{
|
|
{ID: "a", State: "syncing"},
|
|
{ID: "b", State: "error"},
|
|
}
|
|
got := stateFromFolders(folders, false)
|
|
if got != icons.StateError {
|
|
t.Errorf("error should take priority over syncing, got %d", got)
|
|
}
|
|
}
|
|
|
|
func TestStateFromFolders_PausedOverAll(t *testing.T) {
|
|
folders := []FolderInfo{
|
|
{ID: "a", State: "error"},
|
|
{ID: "b", State: "syncing"},
|
|
}
|
|
got := stateFromFolders(folders, true)
|
|
if got != icons.StatePaused {
|
|
t.Errorf("paused should override all states, got %d", got)
|
|
}
|
|
}
|