8e08c73f60
Full-stack Go monolith with embedded React frontend for orchestrating rsync-over-SSH file synchronization with Wake-on-LAN support. Features: - JWT auth (HS256) with bcrypt password hashing - CRUD for machines (with WoL config) and sync_pairs - Ed25519 SSH key generation and known_hosts management - WoL magic packet sender + TCP-connect waiter with backoff - Sync engine: rsync subprocess, per-pair job queue, progress parsing - Homebrew cron parser for scheduled syncs - SSE stream for live job status (queued/waking_up/running/success/failed) - React+TS+Vite+Tailwind SPA embedded via embed.FS - Debian packaging with systemd unit, postinst/prerm/postrm Tech stack: - Go 1.22+ (CGO_ENABLED=0, pure SQLite via modernc.org/sqlite) - chi router for HTTP API - TypeScript + React 18 + Tailwind CSS frontend - Cross-compiled to Linux amd64 for Proxmox LXC deployment Tests: wol (MAC parsing, magic packet), syncengine/queue, scheduler/cron
46 lines
826 B
Go
46 lines
826 B
Go
package syncengine
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestQueue(t *testing.T) {
|
|
q := NewQueue()
|
|
|
|
if q.IsRunning(1) {
|
|
t.Error("queue should be empty")
|
|
}
|
|
|
|
cancelCalled := false
|
|
cancel := func() { cancelCalled = true }
|
|
|
|
err := q.Enqueue(1, 100, cancel)
|
|
if err != nil {
|
|
t.Errorf("Enqueue(1) unexpected error: %v", err)
|
|
}
|
|
|
|
if !q.IsRunning(1) {
|
|
t.Error("queue should contain syncPair 1")
|
|
}
|
|
|
|
jobID, ok := q.GetJobID(1)
|
|
if !ok || jobID != 100 {
|
|
t.Errorf("GetJobID(1) = %d, %v, want 100, true", jobID, ok)
|
|
}
|
|
|
|
err = q.Enqueue(1, 200, nil)
|
|
if err != ErrAlreadyRunning {
|
|
t.Errorf("Enqueue(1) again = %v, want ErrAlreadyRunning", err)
|
|
}
|
|
|
|
q.Cancel(1)
|
|
if !cancelCalled {
|
|
t.Error("Cancel should have called the cancel func")
|
|
}
|
|
|
|
q.Dequeue(1)
|
|
if q.IsRunning(1) {
|
|
t.Error("queue should be empty after Dequeue")
|
|
}
|
|
}
|