test(11-07): cover jobs, scheduler and lagoon seams branch by branch
- conga: TestOutcome*, TestCancelQueuedNeverRuns, TestCancelRunningCancelsCtx, TestStopJobFromWorker, TestManagerPHPSemantics, principal, delay, registration, worker and queue-setting branches; TestQueueClear and TestQueueWork move to commands_test.go with the batch/state and queue-filter cases (coverage 92.5%) - scheduler: validation, ordering, missing catalog, log writer, dueAt - lagoon: TestQueueMigrationsUpDown (River v7 + summer_jobs, rollback, idempotent rerun), OnDatabase isolation, Transaction edges - bonfire TestCallEdges, pact TestCadence
This commit is contained in:
@@ -53,3 +53,51 @@ func TestCall(t *testing.T) {
|
||||
t.Fatal("nil catalog must hold no commands")
|
||||
}
|
||||
}
|
||||
|
||||
// TestCallEdges covers the in-process run edges the scheduler relies on:
|
||||
// empty stdin gives prompt defaults, a nil ctx and a nil writer are
|
||||
// allowed, and a command error is returned as is.
|
||||
func TestCallEdges(t *testing.T) {
|
||||
boom := errors.New("boom")
|
||||
var answer string
|
||||
var confirmed bool
|
||||
var sawCtx bool
|
||||
cmds := []Command{
|
||||
{Name: "acme:ask", Run: func(ctx context.Context, in Input, out Output) error {
|
||||
sawCtx = ctx != nil
|
||||
var err error
|
||||
if answer, err = out.Ask("Name?", "default-name"); err != nil {
|
||||
return err
|
||||
}
|
||||
confirmed, err = out.Confirm("Sure?", true)
|
||||
return err
|
||||
}},
|
||||
{Name: "acme:fail", Run: func(context.Context, Input, Output) error { return boom }},
|
||||
}
|
||||
cases := []struct {
|
||||
name string
|
||||
ctx context.Context
|
||||
command string
|
||||
wantErr error
|
||||
}{
|
||||
{"prompt_defaults", t.Context(), "acme:ask", nil},
|
||||
{"nil_ctx", nil, "acme:ask", nil},
|
||||
{"command_error", t.Context(), "acme:fail", boom},
|
||||
{"unknown", t.Context(), "acme:nope", ErrUnknownCommand},
|
||||
}
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
answer, confirmed, sawCtx = "", false, false
|
||||
err := Call(c.ctx, cmds, c.command, nil, nil)
|
||||
if c.wantErr == nil && err != nil {
|
||||
t.Fatalf("err = %v", err)
|
||||
}
|
||||
if c.wantErr != nil && !errors.Is(err, c.wantErr) {
|
||||
t.Fatalf("err = %v, want %v", err, c.wantErr)
|
||||
}
|
||||
if c.command == "acme:ask" && (answer != "default-name" || !confirmed || !sawCtx) {
|
||||
t.Fatalf("answer %q, confirmed %v, ctx %v; want the prompt defaults and a ctx", answer, confirmed, sawCtx)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user