Skip to content

Commit

Permalink
bonsai
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW committed May 21, 2024
1 parent 4da2b85 commit 125b455
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 16 deletions.
56 changes: 40 additions & 16 deletions operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1142,18 +1142,20 @@ func TestStepResult(t *testing.T) {
}
}

func TestStepOutcome(t *testing.T) {
func TestStepOutcomeAndRun(t *testing.T) {
tests := []struct {
book string
force bool
want []result
book string
force bool
wantOutcome []result
wantRun []bool
}{
{"testdata/book/always_success.yml", false, []result{resultSuccess, resultSuccess, resultSuccess}},
{"testdata/book/always_failure.yml", false, []result{resultSuccess, resultFailure, resultSkipped}},
{"testdata/book/skip_test.yml", false, []result{resultSkipped, resultSuccess}},
{"testdata/book/only_if_included.yml", false, []result{resultSkipped, resultSkipped}},
{"testdata/book/always_failure.yml", true, []result{resultSuccess, resultFailure, resultSuccess}},
{"testdata/book/only_if_included.yml", true, []result{resultSkipped, resultSkipped}},
{"testdata/book/always_success.yml", false, []result{resultSuccess, resultSuccess, resultSuccess}, []bool{true, true, true}},
{"testdata/book/always_failure.yml", false, []result{resultSuccess, resultFailure, resultSkipped}, []bool{true, false, false}},
{"testdata/book/skip_test.yml", false, []result{resultSkipped, resultSuccess}, []bool{false, true}},
{"testdata/book/only_if_included.yml", false, []result{resultSkipped, resultSkipped}, []bool{false, false}},
{"testdata/book/always_failure.yml", true, []result{resultSuccess, resultFailure, resultSuccess}, []bool{true, false, true}},
{"testdata/book/only_if_included.yml", true, []result{resultSkipped, resultSkipped}, []bool{false, false}},
{"testdata/book/always_success_loop.yml", false, []result{resultSuccess, resultSuccess, resultSuccess}, []bool{true, true, true}},
}
ctx := context.Background()
for _, tt := range tests {
Expand All @@ -1165,8 +1167,8 @@ func TestStepOutcome(t *testing.T) {
}
_ = o.Run(ctx)
if o.useMap {
if len(o.store.stepMapKeys) != len(tt.want) {
t.Errorf("got %v\nwant %v", len(o.store.stepMapKeys), len(tt.want))
if len(o.store.stepMapKeys) != len(tt.wantOutcome) {
t.Errorf("got %v\nwant %v", len(o.store.stepMapKeys), len(tt.wantOutcome))
}
i := 0
for _, k := range o.store.stepMapKeys {
Expand All @@ -1175,26 +1177,48 @@ func TestStepOutcome(t *testing.T) {
t.Error("want outcome")
continue
}
want := tt.want[i]
want := tt.wantOutcome[i]
if got != want {
t.Errorf("step[%d] got %v\nwant %v", i, got, want)
}
{
got, ok := o.store.stepMap[k][storeStepKeyRun]
if !ok {
t.Error("want run result")
continue
}
want := tt.wantRun[i]
if got != want {
t.Errorf("step[%d] got %v\nwant %v", i, got, want)
}
}
i++
}
} else {
if len(o.store.steps) != len(tt.want) {
t.Errorf("got %v\nwant %v", len(o.store.steps), len(tt.want))
if len(o.store.steps) != len(tt.wantOutcome) {
t.Errorf("got %v\nwant %v", len(o.store.steps), len(tt.wantOutcome))
}
for i, s := range o.store.steps {
got, ok := s[storeStepKeyOutcome]
if !ok {
t.Error("want outcome")
continue
}
want := tt.want[i]
want := tt.wantOutcome[i]
if got != want {
t.Errorf("step[%d] got %v\nwant %v", i, got, want)
}
{
got, ok := s[storeStepKeyRun]
if !ok {
t.Error("want run result")
continue
}
want := tt.wantRun[i]
if got != want {
t.Errorf("step[%d] got %v\nwant %v", i, got, want)
}
}
}
}
})
Expand Down
9 changes: 9 additions & 0 deletions testdata/book/always_success_loop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
desc: Always success scenario with loop
steps:
-
loop: 3
test: 'true'
-
test: 'true'
-
test: 'true'

0 comments on commit 125b455

Please sign in to comment.