-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror_internal_pkg_test.go
More file actions
47 lines (37 loc) · 989 Bytes
/
error_internal_pkg_test.go
File metadata and controls
47 lines (37 loc) · 989 Bytes
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 xerror
import (
"testing"
"github.com/matryer/is"
)
func TestWrappedArgs(t *testing.T) {
is := is.New(t)
args := wrappedArgs("wrapped err: %w")
is.True(len(args) == 1)
is.Equal(args[0], 1)
}
func TestWrappedArgsAfterOtherArgs(t *testing.T) {
is := is.New(t)
args := wrappedArgs("too many buckets: %d/%d, wrapped err: %w")
is.True(len(args) == 1)
is.Equal(args[0], 3)
}
func TestWrappedArgsBetweenOtherArgs(t *testing.T) {
is := is.New(t)
args := wrappedArgs("service proc: %s failed, wrapped err: %w, lost %d")
is.True(len(args) == 1)
is.Equal(args[0], 2)
}
func TestKindPinned(t *testing.T) {
is := is.New(t)
err := NewWithKind("NETWORK_ERROR", "something went wrong").Pin()
x, ok := err.(*x)
is.True(ok)
is.True(x.isPinned())
}
func TestWrappedErrorHasKindPinned(t *testing.T) {
is := is.New(t)
err := Errorf("wrapped custom err: %w", NewWithKind("WRAPPED_ERROR", "not enough rocks").Pin())
x, ok := err.(*x)
is.True(ok)
is.True(x.isPinned())
}