-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessage_test.go
47 lines (43 loc) · 935 Bytes
/
message_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
package errors
import (
"fmt"
"testing"
"github.com/matryer/is"
)
func TestWithMessage(t *testing.T) {
testCases := []struct {
description string
err error
message string
expected string
}{
{
description: "root-error-with-message",
err: New("root error"),
message: "message error",
expected: "root error, with message \"message error\"",
},
{
description: "nil-error-returns-nil",
err: nil,
},
}
is := is.New(t)
for i, tc := range testCases {
tc := tc
t.Run(fmt.Sprintf("%d:%s", i, tc.description), func(t *testing.T) {
t.Parallel()
actual := WithMessage(tc.err, tc.message)
if tc.err == nil {
is.True(actual == nil)
return
}
is.Equal(tc.expected, actual.Error())
unwrapped := actual.(Message).Unwrap()
is.Equal(tc.err, unwrapped)
var m Message
is.True(As(actual, &m))
is.Equal(tc.message, m.Value)
})
}
}