...
1 package emperror
2
3 import (
4 "errors"
5 "testing"
6 )
7
8 func TestHandleRecovery(t *testing.T) {
9 err := errors.New("error")
10
11 defer HandleRecover(HandlerFunc(func(err error) {
12 if got, want := err.Error(), "error"; got != want {
13 t.Errorf("error does not match the expected one\nactual: %s\nexpected: %s", got, want)
14 }
15 }))
16
17 panic(err)
18 }
19
20 func TestHandle(t *testing.T) {
21 handler := NewTestHandler()
22 err := errors.New("error")
23
24 Handle(handler, err)
25
26 if got, want := handler.LastError(), err; got != want {
27 t.Errorf("error does not match the expected one\nactual: %s\nexpected: %s", got, want)
28 }
29 }
30
31 func TestHandle_Nil(t *testing.T) {
32 handler := NewTestHandler()
33
34 Handle(handler, nil)
35
36 if got := handler.LastError(); got != nil {
37 t.Errorf("unexpected error, received: %s", got)
38 }
39 }
40
View as plain text