Skip to content

Commit

Permalink
improve state logic
Browse files Browse the repository at this point in the history
  • Loading branch information
siller174 committed Sep 9, 2024
1 parent 170a6c9 commit 27f1f70
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion examples/table_test/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ func Test_Array_Timeout(t *testing.T) {
},
Expect: &cute.Expect{
Code: 202,
ExecuteTime: 2,
ExecuteTime: 2 * time.Second,
},
},
}
Expand Down
38 changes: 19 additions & 19 deletions test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,14 @@ func (it *Test) startRepeatableTest(ctx context.Context, t internalT) ResultsHTT

resultState = it.processTestErrors(t, errs)

// we don't want to keep errors if we will retry test
// we have to return to user only errors from last try

// if the test is successful, we break the loop
if resultState == ResultStateSuccess {
break
}

// we want to keep the errors from the previous attempt, so we append them to the new errors
errs = append(errs, errs...)

// if we have a delay, we wait before the next attempt
// and we only wait if we are not at the last attempt
if it.Retry.currentCount != it.Retry.MaxAttempts && it.Retry.Delay != 0 {
Expand All @@ -267,6 +267,20 @@ func (it *Test) startRepeatableTest(ctx context.Context, t internalT) ResultsHTT
}
}

switch resultState {
case ResultStateBroken:
t.BrokenNow()
it.Info(t, "Test broken")
case ResultStateFail:
t.Fail()
it.Error(t, "Test failed")
case resultStateFailNow:
t.FailNow()
it.Error(t, "Test failed")
case ResultStateSuccess:
it.Info(t, "Test finished successfully")
}

return newTestResult(it.Name, resp, resultState, errs)
}

Expand All @@ -291,8 +305,8 @@ func (it *Test) startTestInsideStep(ctx context.Context, t internalT) ResultsHTT

// processTestErrors returns flag, which mean finish test or not.
// If test has only optional errors, than test will be success
// If test has broken errors, than test will be broken on allure and executed t.FailNow().
// If test has require errors, than test will be failed on allure and executed t.FailNow().
// If test has broken errors, than test will be broken on allure
// If test has require errors, than test will be failed on allure
func (it *Test) processTestErrors(t internalT, errs []error) ResultState {
if len(errs) == 0 {
it.Info(t, "Test finished successfully")
Expand Down Expand Up @@ -354,20 +368,6 @@ func (it *Test) processTestErrors(t internalT, errs []error) ResultState {
it.Error(t, "Test finished with %v errors", countNotOptionalErrors)
}

switch state {
case ResultStateBroken:
t.BrokenNow()
it.Info(t, "Test broken")
case ResultStateFail:
t.Fail()
it.Error(t, "Test failed")
case resultStateFailNow:
t.FailNow()
it.Error(t, "Test failed")
case ResultStateSuccess:
it.Info(t, "Test finished successfully")
}

return state
}

Expand Down

0 comments on commit 27f1f70

Please sign in to comment.