-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfaults_test.go
127 lines (121 loc) · 2.34 KB
/
faults_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package faults_test
import (
"testing"
"github.com/deixis/faults"
)
// TestIs ensures all `Is*` functions return true for the error they are
// supposed to match.
func TestIs(t *testing.T) {
table := []struct {
Error error
Is func(err error) bool
}{
{
Error: faults.NotFound,
Is: faults.IsNotFound,
},
{
Error: faults.PermissionDenied,
Is: faults.IsPermissionDenied,
},
{
Error: faults.Unauthenticated,
Is: faults.IsUnauthenticated,
},
{
Error: faults.Bad(),
Is: faults.IsBad,
},
{
Error: faults.FailedPrecondition(),
Is: faults.IsFailedPrecondition,
},
{
Error: faults.Aborted(),
Is: faults.IsAborted,
},
{
Error: faults.Unavailable(0),
Is: faults.IsUnavailable,
},
{
Error: faults.ResourceExhausted(),
Is: faults.IsResourceExhausted,
},
}
for i, test := range table {
if !test.Is(test.Error) {
t.Errorf("%d - expect error Is to return true for error %s", i, test.Error)
}
}
}
// TestAs ensures all `As*` functions return true for the error they are
// supposed to match.
func TestAs(t *testing.T) {
table := []struct {
Error error
As func(err error) bool
}{
{
Error: faults.NotFound,
As: func(err error) bool {
_, ok := faults.AsNotFound(err)
return ok
},
},
{
Error: faults.PermissionDenied,
As: func(err error) bool {
_, ok := faults.AsPermissionDenied(err)
return ok
},
},
{
Error: faults.Unauthenticated,
As: func(err error) bool {
_, ok := faults.AsUnauthenticated(err)
return ok
},
},
{
Error: faults.Bad(),
As: func(err error) bool {
_, ok := faults.AsBad(err)
return ok
},
},
{
Error: faults.FailedPrecondition(),
As: func(err error) bool {
_, ok := faults.AsFailedPrecondition(err)
return ok
},
},
{
Error: faults.Aborted(),
As: func(err error) bool {
_, ok := faults.AsAborted(err)
return ok
},
},
{
Error: faults.Unavailable(0),
As: func(err error) bool {
_, ok := faults.AsUnavailable(err)
return ok
},
},
{
Error: faults.ResourceExhausted(),
As: func(err error) bool {
_, ok := faults.AsResourceExhausted(err)
return ok
},
},
}
for i, test := range table {
if !test.As(test.Error) {
t.Errorf("%d - expect error As to return true for error %s", i, test.Error)
}
}
}