-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrortypes_test.go
94 lines (79 loc) · 1.96 KB
/
errortypes_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
// Licensed under the GPLv3, see LICENCE file for details.
package bulkerrs_test
import (
"testing"
"github.com/eurielec/bulkerrs"
"github.com/juju/errors"
"github.com/stretchr/testify/assert"
)
var isXFns = [...]bulkerrs.IsXFn{
bulkerrs.IsTimeout,
bulkerrs.IsNotFound,
bulkerrs.IsUserNotFound,
bulkerrs.IsUnauthorized,
bulkerrs.IsNotImplemented,
bulkerrs.IsAlreadyExists,
bulkerrs.IsNotSupported,
bulkerrs.IsNotValid,
bulkerrs.IsNotProvisioned,
bulkerrs.IsNotAssigned,
bulkerrs.IsBadRequest,
bulkerrs.IsMethodNotAllowed,
bulkerrs.IsForbidden,
}
var newXFns = [...]bulkerrs.NewXFn{
errors.NewTimeout,
errors.NewNotFound,
errors.NewUserNotFound,
errors.NewUnauthorized,
errors.NewNotImplemented,
errors.NewAlreadyExists,
errors.NewNotSupported,
errors.NewNotValid,
errors.NewNotProvisioned,
errors.NewNotAssigned,
errors.NewBadRequest,
errors.NewMethodNotAllowed,
errors.NewForbidden,
}
func TestBase(t *testing.T) {
// Check errors type of a nil
var errs *bulkerrs.Errs
for _, isx := range isXFns {
assert.False(t, isx(errs), "Should return false")
}
// Check errors type of a JujuErr
for i, newx := range newXFns {
for j, isx := range isXFns {
assert.Equal(t, i == j, isx(newx(nil, "")), "Should return only one true in loop")
}
}
}
func TestX(t *testing.T) {
for i := 0; i < len(isXFns); i++ {
// New Errs
errs := bulkerrs.NewErr()
// Fill with errors
for j, newx := range newXFns {
errs.AppendIfX(i == j, newx, "", nil)
}
// New Errs -> error
err := errs.ToError()
// Check errors type
for j, isx := range isXFns {
assert.Equal(t, i == j, isx(err), "Should return only one true in loop")
}
// New Errs
errs = bulkerrs.NewErr()
// Fill with error
for j, newx := range newXFns {
errs.AppendIfX(i != j, newx, "", nil)
}
// New Errs -> error
err = errs.ToError()
// Check errors type
for j, isx := range isXFns {
assert.Equal(t, i != j, isx(err), "Should return only one false in loop")
}
}
}