-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors_test.go
54 lines (43 loc) · 1.32 KB
/
errors_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package errors
import (
"errors"
"fmt"
"testing"
"github.com/stretchr/testify/require"
)
func TestWrap(t *testing.T) {
err := errors.New("oops, I did it again!!")
wrapped := Wrap(err, "ERR")
require.Equal(t, "ERR: oops, I did it again!!", wrapped.Error())
me, ok := wrapped.(*MyError)
require.True(t, ok)
require.Equal(t, err, me.origErr)
require.Equal(t, "ERR: oops, I did it again!!", me.message)
wrapped = testWrapThirdCaller()
me = wrapped.(*MyError)
expectedNotes := []string{
"testWrapFirstCaller",
"testWrapSecondCaller",
"testWrapThirdCaller",
}
require.Equal(t, len(expectedNotes), len(me.notes))
for i := range me.notes {
require.Equal(t, expectedNotes[i], me.notes[i])
}
expectedNotesInString := "testWrapFirstCaller -> testWrapSecondCaller -> testWrapThirdCaller"
require.Equal(t, expectedNotesInString, me.NotesInString())
expectedMessage := "testWrapFirstCaller: oops, something error!!"
require.Equal(t, expectedMessage, me.message)
}
func testWrapThirdCaller() error {
return Wrap(testWrapSecondCaller(), "testWrapThirdCaller")
}
func testWrapSecondCaller() error {
return Wrap(testWrapFirstCaller(), "testWrapSecondCaller")
}
func testWrapFirstCaller() error {
return Wrap(testWrapOrigin(), "testWrapFirstCaller")
}
func testWrapOrigin() error {
return fmt.Errorf("oops, something error!!")
}