mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-02 19:17:10 +00:00
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:
1 parent
d9f96602d9
commit
577993b540
14 files changed
+233
-1282
No files matched your search
@@ -2,10 +2,6 @@ package runner
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -43,34 +39,13 @@ func TestRunner_LogsAndExceptionsLandInTheTrace(t *testing.T) {
|
||||
Message: "FATAL EXCEPTION: main",
|
||||
}}
|
||||
|
||||
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: 1,
|
||||
Driver: &throwingDriver{Driver: state.mock},
|
||||
Verifier: state.verifier,
|
||||
TraceWriter: state.writer,
|
||||
}); err != nil {
|
||||
t.Fatalf("Run: %v", err)
|
||||
}
|
||||
state.run(t, Options{
|
||||
Duration: 100 * time.Millisecond,
|
||||
MaxSteps: 1,
|
||||
Driver: &throwingDriver{Driver: state.mock},
|
||||
})
|
||||
|
||||
body, err := os.ReadFile(
|
||||
filepath.Join(state.writer.Directory(), "trace.jsonl"),
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
line := strings.SplitN(strings.TrimSpace(string(body)), "\n", 2)[0]
|
||||
var stored struct {
|
||||
TraceVersion int `json:"trace_version"`
|
||||
Logs []trace.LogEntry `json:"logs"`
|
||||
Exceptions []trace.Exception `json:"exceptions"`
|
||||
}
|
||||
if err := json.Unmarshal([]byte(line), &stored); err != nil {
|
||||
t.Fatalf("decode trace line: %v\n%s", err, line)
|
||||
}
|
||||
stored := readTraceLines(t, state.writer.Directory())[0]
|
||||
if stored.TraceVersion != trace.TraceVersion {
|
||||
t.Errorf(
|
||||
"trace_version = %d, want %d; an old trace could not be told apart",
|
||||
|
||||
Reference in new issue
Block a user