-
-
Notifications
You must be signed in to change notification settings - Fork 70
/
errors_test.go
42 lines (33 loc) · 811 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
package atreugo
import (
"errors"
"testing"
)
func Test_wrapError(t *testing.T) {
err := errors.New("some error")
err2 := wrapError(err, "test")
if err2 == nil {
t.Error("Expected error, got nil")
}
wantStrEr := "test: some error"
if strErr := err2.Error(); strErr != wantStrEr {
t.Errorf("result %v, want %v", strErr, wantStrEr)
}
if !errors.Is(err2, err) {
t.Error("Expected different error")
}
}
func Test_wrapErrorf(t *testing.T) {
err := errors.New("some error")
err2 := wrapErrorf(err, "test %s", "fail")
if err2 == nil {
t.Error("Expected error, got nil")
}
wantStrEr := "test fail: some error"
if strErr := err2.Error(); strErr != wantStrEr {
t.Errorf("result %v, want %v", strErr, wantStrEr)
}
if !errors.Is(err2, err) {
t.Error("Expected different error")
}
}