-
Notifications
You must be signed in to change notification settings - Fork 2
/
vice_test.go
60 lines (50 loc) · 1.16 KB
/
vice_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
package vice
import (
"errors"
"testing"
)
func TestVice(t *testing.T) {
for _, v := range vices {
err := New(v, "test")
if !Is(err, v) {
t.Error("Did not create correct error form")
}
inner := errors.New("inside")
err = Wrap(inner, v, "wrapping")
if !Is(err, v) {
t.Error("Did not create correct error form")
}
}
}
func TestNoVice(t *testing.T) {
t.Run("with Vice error", func(t *testing.T) {
for i, v := range vices {
err := New(v, "test")
if Is(err, NoVice) {
t.Errorf("%d element should be concrete Vice type", i)
}
}
})
t.Run("with NoVice error", func(t *testing.T) {
if !Is(errors.New("test"), NoVice) {
t.Errorf("Expected custom error to be NoVice")
}
if !Is(New(NoVice, "test"), NoVice) {
t.Errorf("Expected NoVice error to be NoVice")
}
})
}
func TestWrapNil(t *testing.T) {
inner := errors.New("no auth")
wrapped := Wrap(inner, AuthRequired, "wrapping")
if wrapped == nil {
t.Error("Wrapped error should not be nil")
}
maybeError := func() error {
return nil
}()
wrapped = Wrap(maybeError, Conflict, "try wrapping")
if wrapped != nil {
t.Error("Wrapping a nil error should return nil")
}
}