Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kevindiu authored and actions-user committed Jun 11, 2020
1 parent eb4e44d commit 53c863a
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions internal/safety/safety_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,16 @@ func TestRecoverFunc(t *testing.T) {
afterFunc func(args)
}
defaultCheckFunc := func(w want, got func() error) error {
gotErr := got()

// if wantPanic is not nil then the panic should be recovered and this line should not be executed
if w.wantPanic != nil {
return errors.Errorf("wantPanic is not nil, but got return error: %v", gotErr)
}

if (w.want == nil && got != nil) || (w.want != nil && got == nil) {
return errors.Errorf("got = %v, want %v", got, w)
}
gotErr := got()
wantErr := w.want()
if !errors.Is(gotErr, wantErr) {
return errors.Errorf("got error= %v, want error= %v", gotErr, wantErr)
Expand Down Expand Up @@ -133,7 +139,6 @@ func TestRecoverFunc(t *testing.T) {
}
if want := w.wantPanic(); !errors.Is(want, panicErr) {
tt.Errorf("want: %v, got: %v", want, panicErr)
return
}
}(test.want, tt)

Expand All @@ -148,12 +153,8 @@ func TestRecoverFunc(t *testing.T) {
}

got := RecoverFunc(test.args.fn)
if test.want.wantPanic == nil {
if err := test.checkFunc(test.want, got); err != nil {
tt.Errorf("error = %v", err)
}
} else {
got()
if err := test.checkFunc(test.want, got); err != nil {
tt.Errorf("error = %v", err)
}
})
}
Expand Down

0 comments on commit 53c863a

Please sign in to comment.