test(runner): retire the scaffolding the package grew by copying

Four consolidations, no assertion changed and the same 217 tests passing:

harness gains run and tryRun, retiring 68 copies of context.WithTimeout plus
Run(ctx, Options{}) plus an error check. The seven sites whose error check said
something specific keep their own wording.

mock.FailurePlan retires six wrapper drivers that were the same seven-line
method with a different error constant. The three that need more than an error
on call N stay.

traceStepLine absorbs the 15 local trace-line declarations and readTraceLines is
now the only reader. No local copy disagreed with internal/trace about a JSON
tag. Three raw readers stay on purpose: one decodes a real trace.Step, one
snapshots bytes, one asserts on raw JSON text.

One embeddable base carries the five V8-path methods the five web fakes each
redeclared.
This commit is contained in:
pj committed 2026-08-22 21:39:22 +05:30
1 parent d9f96602d9
commit 577993b540
14 files changed
+233 -1282

No files matched your search

+4 -35
View File
@@ -1,17 +1,12 @@
package runner
import (
"bufio"
"context"
"encoding/json"
"os"
"path/filepath"
"testing"
"time"
"github.com/priyanshujain/sanderling/internal/driver"
mockdriver "github.com/priyanshujain/sanderling/internal/driver/mock"
"github.com/priyanshujain/sanderling/internal/trace"
)
// navigatingDriver reports one navigation per step, the way a page that submits
@@ -33,46 +28,20 @@ func TestRunner_TheTraceRecordsThatThePageNavigated(t *testing.T) {
const url = "http://127.0.0.1/index.html?"
navigating := &navigatingDriver{Driver: state.mock, url: url}
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if _, err := Run(ctx, Options{
Duration: 100 * time.Millisecond,
IdleTimeout: 20 * time.Millisecond,
MaxSteps: 3,
Driver: navigating,
Verifier: state.verifier,
TraceWriter: state.writer,
}); err != nil {
t.Fatalf("Run: %v", err)
}
state.run(t, Options{Duration: 100 * time.Millisecond, MaxSteps: 3, Driver: navigating})
if err := state.writer.Close(); err != nil {
t.Fatalf("close trace: %v", err)
}
file, err := os.Open(filepath.Join(state.writer.Directory(), "trace.jsonl"))
if err != nil {
t.Fatal(err)
}
defer file.Close()
recorded := 0
scanner := bufio.NewScanner(file)
scanner.Buffer(make([]byte, 0, 64*1024), 8*1024*1024)
for scanner.Scan() {
var step struct {
Index int `json:"step"`
Navigations []trace.Navigation `json:"navigations"`
}
if err := json.Unmarshal(scanner.Bytes(), &step); err != nil {
t.Fatalf("trace line decode: %v", err)
}
for _, step := range readTraceLines(t, state.writer.Directory()) {
for _, navigation := range step.Navigations {
recorded++
if navigation.URL != url {
t.Errorf("step %d records navigation to %q, want %q", step.Index, navigation.URL, url)
t.Errorf("step %d records navigation to %q, want %q", step.Step, navigation.URL, url)
}
if navigation.UnixMillis == 0 {
t.Errorf("step %d records a navigation with no timestamp", step.Index)
t.Errorf("step %d records a navigation with no timestamp", step.Step)
}
}
}