-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors_test.go
48 lines (43 loc) · 906 Bytes
/
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
package errors_test
import (
"testing"
"maragu.dev/errors"
)
func TestWrap(t *testing.T) {
t.Run("returns wrapped error", func(t *testing.T) {
err := errors.Wrap(errors.New("oops"), "wrap this")
if err == nil {
t.FailNow()
}
if err.Error() != "wrap this: oops" {
t.FailNow()
}
unwrappedErr := errors.Unwrap(err)
if unwrappedErr == nil {
t.FailNow()
}
if unwrappedErr.Error() != "oops" {
t.FailNow()
}
})
t.Run("can use format parameters", func(t *testing.T) {
err := errors.Wrap(errors.New("whoops"), "error in %v", 123)
if err == nil {
t.FailNow()
}
if err.Error() != "error in 123: whoops" {
t.FailNow()
}
})
}
func TestNewf(t *testing.T) {
t.Run("formats an error", func(t *testing.T) {
err := errors.Newf("oops, error code %v", 100)
if err == nil {
t.FailNow()
}
if err.Error() != "oops, error code 100" {
t.FailNow()
}
})
}