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
73 lines
1.7 KiB
Go
73 lines
1.7 KiB
Go
package wol
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestParseMAC(t *testing.T) {
|
|
tests := []struct {
|
|
input string
|
|
wantOK bool
|
|
wantBytes [6]byte
|
|
}{
|
|
{"AA:BB:CC:DD:EE:FF", true, [6]byte{0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF}},
|
|
{"aa:bb:cc:dd:ee:ff", true, [6]byte{0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF}},
|
|
{"AA-BB-CC-DD-EE-FF", true, [6]byte{0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF}},
|
|
{"11:22:33:44:55:66", true, [6]byte{0x11, 0x22, 0x33, 0x44, 0x55, 0x66}},
|
|
{"not:a:mac:addre", false, [6]byte{}},
|
|
{"GG:HH:II:JJ:KK:LL", false, [6]byte{}},
|
|
{"aa:bb:cc:dd", false, [6]byte{}},
|
|
{"", false, [6]byte{}},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
mac, err := ParseMAC(tt.input)
|
|
if tt.wantOK {
|
|
if err != nil {
|
|
t.Errorf("ParseMAC(%q) unexpected error: %v", tt.input, err)
|
|
continue
|
|
}
|
|
if mac != tt.wantBytes {
|
|
t.Errorf("ParseMAC(%q) = %v, want %v", tt.input, mac, tt.wantBytes)
|
|
}
|
|
} else {
|
|
if err == nil {
|
|
t.Errorf("ParseMAC(%q) expected error, got nil", tt.input)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestFormatMAC(t *testing.T) {
|
|
mac := [6]byte{0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF}
|
|
got := FormatMAC(mac)
|
|
want := "aa:bb:cc:dd:ee:ff"
|
|
if got != want {
|
|
t.Errorf("FormatMAC() = %q, want %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestBuildMagicPacket(t *testing.T) {
|
|
mac := [6]byte{0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF}
|
|
packet := BuildMagicPacket(mac)
|
|
|
|
if len(packet) != 102 {
|
|
t.Errorf("BuildMagicPacket length = %d, want 102", len(packet))
|
|
}
|
|
|
|
for i := 0; i < 6; i++ {
|
|
if packet[i] != 0xFF {
|
|
t.Errorf("packet[%d] = %02x, want FF", i, packet[i])
|
|
}
|
|
}
|
|
|
|
for i := 0; i < 16; i++ {
|
|
offset := 6 + i*6
|
|
for j := 0; j < 6; j++ {
|
|
if packet[offset+j] != mac[j] {
|
|
t.Errorf("packet[%d] = %02x, want %02x (rep %d)", offset+j, packet[offset+j], mac[j], i)
|
|
}
|
|
}
|
|
}
|
|
}
|