Files
felhom.eu/hub/cmd/hub/r173_wiring_test.go
T

48 lines
1.4 KiB
Go

package main
import (
"go/ast"
"go/parser"
"go/token"
"strconv"
"testing"
)
// R-173 seam wiring: main() must schedule the nightly db snapshot — a scheduleDaily call named "db-snapshot" at
// "02:00", before DooPlex's 02:30 push — and must run the start-up catch-up (dbsnap.NeedsCatchUp). Without them the
// dbsnap package exists and DooPlex pushes nothing new. RED-PROOF: delete either call → this test fails.
func TestR173_MainSchedulesTheDBSnapshot(t *testing.T) {
f, err := parser.ParseFile(token.NewFileSet(), "main.go", nil, 0)
if err != nil {
t.Fatal(err)
}
scheduled, catchUp := false, false
ast.Inspect(f, func(n ast.Node) bool {
c, ok := n.(*ast.CallExpr)
if !ok {
return true
}
if id, ok := c.Fun.(*ast.Ident); ok && id.Name == "scheduleDaily" && len(c.Args) >= 3 {
name, _ := c.Args[1].(*ast.BasicLit)
at, _ := c.Args[2].(*ast.BasicLit)
if name != nil && at != nil {
n, _ := strconv.Unquote(name.Value)
a, _ := strconv.Unquote(at.Value)
if n == "db-snapshot" && a == "02:00" {
scheduled = true
}
}
}
if sel, ok := c.Fun.(*ast.SelectorExpr); ok && sel.Sel.Name == "NeedsCatchUp" {
catchUp = true
}
return true
})
if !scheduled {
t.Error(`cmd/hub/main.go never calls scheduleDaily(ctx, "db-snapshot", "02:00", …) — no nightly snapshot`)
}
if !catchUp {
t.Error("cmd/hub/main.go never calls dbsnap.NeedsCatchUp — a pod down at 02:00 leaves a stale snapshot")
}
}