-
Notifications
You must be signed in to change notification settings - Fork 14
/
errors_with_message_test.go
61 lines (48 loc) · 1.4 KB
/
errors_with_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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package errors
import (
"testing"
)
func TestWithMessage(t *testing.T) {
origErr := NewPlain("something went wrong")
err := WithMessage(origErr, "error")
t.Parallel()
t.Run("error_message", func(t *testing.T) {
checkErrorMessage(t, err, "error: something went wrong")
})
t.Run("unwrap", func(t *testing.T) {
checkUnwrap(t, err, origErr)
})
t.Run("format", func(t *testing.T) {
checkFormat(t, err, map[string][]string{
"%s": {"error: something went wrong"},
"%q": {`error: something went wrong`}, // TODO: quotes?
"%v": {"error: something went wrong"},
"%+v": {"something went wrong", "error"},
})
})
t.Run("nil", func(t *testing.T) {
checkErrorNil(t, WithMessage(nil, "error"))
})
}
func TestWithMessagef(t *testing.T) {
origErr := NewPlain("something went wrong")
err := WithMessagef(origErr, "%s", "error")
t.Parallel()
t.Run("error_message", func(t *testing.T) {
checkErrorMessage(t, err, "error: something went wrong")
})
t.Run("unwrap", func(t *testing.T) {
checkUnwrap(t, err, origErr)
})
t.Run("format", func(t *testing.T) {
checkFormat(t, err, map[string][]string{
"%s": {"error: something went wrong"},
"%q": {`error: something went wrong`}, // TODO: quotes?
"%v": {"error: something went wrong"},
"%+v": {"something went wrong", "error"},
})
})
t.Run("nil", func(t *testing.T) {
checkErrorNil(t, WithMessagef(nil, "%s", "error"))
})
}