-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support
defer:
for deferring steps in a runbook
- Loading branch information
Showing
9 changed files
with
241 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package runn | ||
|
||
const deferSectionKey = "defer" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package runn | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
) | ||
|
||
func TestDeferRun(t *testing.T) { | ||
book := "testdata/book/defer.yml" | ||
ctx := context.Background() | ||
o, err := New(Book(book)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if err := o.Run(ctx); err == nil { | ||
t.Fatal("expected error") | ||
} | ||
if want := 8; len(o.store.steps) != want { | ||
t.Errorf("o.store.steps got %v, want %v", len(o.store.steps), want) | ||
} | ||
r := o.Result() | ||
if want := 8; len(r.StepResults) != want { | ||
t.Errorf("r.StepResults got %v, want %v", len(r.StepResults), want) | ||
} | ||
|
||
t.Run("main steps", func(t *testing.T) { | ||
wantResults := []struct { | ||
desc string | ||
skipped bool | ||
err bool | ||
}{ | ||
{"step 1", false, false}, | ||
{"include step", false, false}, | ||
{"step 2", false, false}, | ||
{"step 3", false, true}, | ||
{"step 4", true, false}, | ||
{"defererd step c", false, false}, | ||
{"defererd step b", false, true}, | ||
{"defererd step a", false, false}, | ||
} | ||
for i, want := range wantResults { | ||
got := r.StepResults[i] | ||
if got.Desc != want.desc { | ||
t.Errorf("got %v, want %v", got.Desc, want.desc) | ||
} | ||
if got.Skipped != want.skipped { | ||
t.Errorf("got %v, want %v", got.Skipped, want.skipped) | ||
} | ||
if (got.Err == nil) == want.err { | ||
t.Errorf("got %v, want %v", got.Err, want.err) | ||
} | ||
} | ||
}) | ||
|
||
t.Run("include steps", func(t *testing.T) { | ||
wantResults := []struct { | ||
desc string | ||
skipped bool | ||
err bool | ||
}{ | ||
{"included step 1", false, false}, | ||
{"included step 2", false, false}, | ||
{"included defererd step d", false, false}, | ||
} | ||
|
||
for i, want := range wantResults { | ||
got := r.StepResults[1].IncludedRunResults[0].StepResults[i] | ||
if got.Desc != want.desc { | ||
t.Errorf("got %v, want %v", got.Desc, want.desc) | ||
} | ||
if got.Skipped != want.skipped { | ||
t.Errorf("got %v, want %v", got.Skipped, want.skipped) | ||
} | ||
if (got.Err == nil) == want.err { | ||
t.Errorf("got %v, want %v", got.Err, want.err) | ||
} | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.