-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpredefined_test.go
More file actions
61 lines (53 loc) · 1.75 KB
/
predefined_test.go
File metadata and controls
61 lines (53 loc) · 1.75 KB
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
package errors
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
const msg = "msg"
var rootErr = fmt.Errorf(msg)
var preErrors = []*annotated{
{rootErr, NotFound, msg, []Any{resourceInfo}},
{rootErr, InvalidArgument, msg, []Any{badRequest}},
{rootErr, FailedPrecondition, msg, []Any{preconditionFailure}},
{rootErr, OutOfRange, msg, []Any{badRequest}},
{rootErr, Unauthenticated, msg, []Any{errInfo}},
{rootErr, PermissionDenied, msg, []Any{errInfo}},
{rootErr, Aborted, msg, []Any{errInfo}},
{rootErr, AlreadyExists, msg, []Any{resourceInfo}},
{rootErr, ResourceExhausted, msg, []Any{quotaFailure}},
{rootErr, Cancelled, msg, nil},
{rootErr, DataLoss, msg, []Any{debugInfo}},
{rootErr, Unknown, msg, []Any{debugInfo}},
{rootErr, Internal, msg, []Any{debugInfo}},
{rootErr, Unimplemented, msg, nil},
{rootErr, Unavailable, msg, []Any{debugInfo}},
{rootErr, DeadlineExceeded, msg, []Any{debugInfo}},
}
func TestPredefined(t *testing.T) {
errors := []error{
WithNotFound(rootErr, resourceInfo),
WithBadRequest(rootErr, badRequest),
WithFailedPrecondition(rootErr, preconditionFailure),
WithOutOfRange(rootErr, badRequest),
WithUnauthenticated(rootErr, errInfo),
WithPermissionDenied(rootErr, errInfo),
WithAborted(rootErr, errInfo),
WithAlreadyExists(rootErr, resourceInfo),
WithResourceExhausted(rootErr, quotaFailure),
WithCancelled(rootErr),
WithDataLoss(rootErr, debugInfo),
WithUnknown(rootErr, debugInfo),
WithInternal(rootErr, debugInfo),
WithUnimplemented(rootErr),
WithUnavailable(rootErr, debugInfo),
WithDeadlineExceeded(rootErr, debugInfo),
}
for i, err := range errors {
assert.Equal(t, preErrors[i], err)
}
}
func TestNil(t *testing.T) {
err := WithUnknown(nil, DebugInfo{})
assert.NoError(t, err)
}