sketch_test.go
package main
import (
"sort"
"testing"
"github.com/warpfork/go-testmark"
)
// TestSketchSnapshots pins the sketch SVG bytes for the "test" seed, one fixture hunk
// per asset in testdata/sketch.md. The point is byte-stability: caches and the visual
// identity both rest on the generators never drifting by accident.
// Run with -testmark.regen after a deliberate wobble change, and review via git diff.
func TestSketchSnapshots(t *testing.T) {
doc, err := testmark.ReadFile("testdata/sketch.md")
if err != nil {
t.Fatalf("reading fixtures: %v", err)
}
assets := sketchAssets("test")
names := make([]string, 0, len(assets))
for name := range assets {
names = append(names, name)
}
sort.Strings(names)
var pa testmark.PatchAccumulator
for _, name := range names {
t.Run(name, func(t *testing.T) {
hunk, ok := doc.HunksByName[name]
if !ok {
t.Fatalf("no fixture hunk for asset %q; add an empty code block under that heading", name)
}
if *testmark.Regen {
pa.AppendPatchIfBodyDiffers(hunk.Hunk, assets[name])
} else if string(hunk.Hunk.Body) != string(assets[name]) {
t.Errorf("asset %q drifted from its snapshot", name)
}
})
}
if len(doc.HunksByName) != len(assets) {
t.Errorf("fixture has %d hunks but the generator makes %d assets; they should match one to one", len(doc.HunksByName), len(assets))
}
if *testmark.Regen {
if err := pa.WriteFileWithPatches(doc, "testdata/sketch.md"); err != nil {
t.Fatal(err)
}
}
}
sketch_test.go · 1.4 KiB · 2d5549287a