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>
68 lines
1.7 KiB
Go
68 lines
1.7 KiB
Go
package monitor
|
|
|
|
import (
|
|
"testing"
|
|
|
|
st "git.davoryn.de/calic/syncwarden/internal/syncthing"
|
|
)
|
|
|
|
func TestFolderTracker_UpdateFromConfig(t *testing.T) {
|
|
ft := NewFolderTracker()
|
|
ft.UpdateFromConfig([]st.FolderConfig{
|
|
{ID: "docs", Label: "Documents", Path: "/home/user/docs"},
|
|
{ID: "photos", Label: "Photos", Path: "/home/user/photos"},
|
|
})
|
|
|
|
folders := ft.Folders()
|
|
if len(folders) != 2 {
|
|
t.Fatalf("expected 2 folders, got %d", len(folders))
|
|
}
|
|
if folders[0].Label != "Documents" {
|
|
t.Errorf("expected label 'Documents', got %q", folders[0].Label)
|
|
}
|
|
if folders[0].State != "unknown" {
|
|
t.Errorf("initial state should be 'unknown', got %q", folders[0].State)
|
|
}
|
|
}
|
|
|
|
func TestFolderTracker_EmptyLabelFallback(t *testing.T) {
|
|
ft := NewFolderTracker()
|
|
ft.UpdateFromConfig([]st.FolderConfig{
|
|
{ID: "my-folder", Label: "", Path: "/data"},
|
|
})
|
|
|
|
folders := ft.Folders()
|
|
if folders[0].Label != "my-folder" {
|
|
t.Errorf("empty label should fall back to ID, got %q", folders[0].Label)
|
|
}
|
|
}
|
|
|
|
func TestFolderTracker_UpdateStatus(t *testing.T) {
|
|
ft := NewFolderTracker()
|
|
ft.UpdateFromConfig([]st.FolderConfig{
|
|
{ID: "docs", Label: "Docs", Path: "/docs"},
|
|
})
|
|
|
|
ft.UpdateStatus("docs", "syncing")
|
|
|
|
folders := ft.Folders()
|
|
if folders[0].State != "syncing" {
|
|
t.Errorf("expected 'syncing', got %q", folders[0].State)
|
|
}
|
|
}
|
|
|
|
func TestFolderTracker_UpdateStatusNonexistent(t *testing.T) {
|
|
ft := NewFolderTracker()
|
|
ft.UpdateFromConfig([]st.FolderConfig{
|
|
{ID: "docs", Label: "Docs", Path: "/docs"},
|
|
})
|
|
|
|
// Should not panic
|
|
ft.UpdateStatus("nonexistent", "idle")
|
|
|
|
folders := ft.Folders()
|
|
if folders[0].State != "unknown" {
|
|
t.Errorf("existing folder should be unchanged, got %q", folders[0].State)
|
|
}
|
|
}
|