feat(watchdog): separate watchdog from startup
- Add /api/v1/watchdog to enable/disable - Scheduled task now runs every 15 minutes - Use schtasks command line instead of XML - Dashboard shows watchdog enabled state - Preserve watchdog state during install
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package startup
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestEnsureTaskTR(t *testing.T) {
|
||||
t.Parallel()
|
||||
cases := []struct {
|
||||
exe string
|
||||
want string
|
||||
}{
|
||||
{`C:\Users\me\AppData\Roaming\win64_mp\win64_mp.exe`, `C:\Users\me\AppData\Roaming\win64_mp\win64_mp.exe -ensure`},
|
||||
{`C:\Users\John Doe\win64_mp.exe`, `C:\Users\John Doe\win64_mp.exe -ensure`},
|
||||
{`"C:\win64_mp.exe"`, `C:\win64_mp.exe -ensure`},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
if got := ensureTaskTR(tc.exe); got != tc.want {
|
||||
t.Fatalf("ensureTaskTR(%q) = %q, want %q", tc.exe, got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSchtasksCreateCmdLine(t *testing.T) {
|
||||
t.Parallel()
|
||||
tr := ensureTaskTR(`C:\Users\John Doe\win64_mp.exe`)
|
||||
got := schtasksCreateCmdLine("win64_mp", tr)
|
||||
if !strings.Contains(got, `/TN win64_mp`) {
|
||||
t.Fatalf("missing task name: %q", got)
|
||||
}
|
||||
if !strings.Contains(got, `/SC MINUTE /MO 15 /RL LIMITED`) {
|
||||
t.Fatalf("missing schedule: %q", got)
|
||||
}
|
||||
wantTR := `/TR "C:\Users\John Doe\win64_mp.exe -ensure"`
|
||||
if !strings.Contains(got, wantTR) {
|
||||
t.Fatalf("TR quoting wrong:\n got: %q\nwant: %q", got, wantTR)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user