-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patherrors_test.go
More file actions
57 lines (50 loc) · 1.6 KB
/
errors_test.go
File metadata and controls
57 lines (50 loc) · 1.6 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
package confire_test
import (
"testing"
"go.rtnl.ai/confire"
"go.rtnl.ai/confire/assert"
"go.rtnl.ai/confire/errors"
)
func TestParserError(t *testing.T) {
testCases := []struct {
err error
ok bool
}{
{errors.ErrInvalidSpecification, false},
{&errors.ParseError{Source: "a", Field: "b", Type: "c", Value: "d", Err: errors.ErrNotAStruct}, true},
{errors.Required("", "foo"), false},
{errors.Invalid("", "foo", "bar"), false},
{errors.Parse("", "foo", errors.ErrNotExported), false},
{errors.Wrap("", "foo", "bar", errors.ErrNotSettable, "qux"), false},
}
for _, tc := range testCases {
target, ok := confire.ParseError(tc.err)
if tc.ok {
assert.True(t, ok)
assert.Assert(t, target != nil, "expected target to be not nil")
} else {
assert.False(t, ok)
assert.Assert(t, target == nil, "expected target to be nil")
}
}
}
func TestIsParserError(t *testing.T) {
testCases := []struct {
err error
assert assert.BoolAssertion
}{
{errors.ErrInvalidSpecification, assert.False},
{errors.ErrNotAStruct, assert.False},
{errors.ErrNotExported, assert.False},
{errors.ErrNotSettable, assert.False},
{&errors.ParseError{}, assert.True},
{&errors.ParseError{Source: "a", Field: "b", Type: "c", Value: "d", Err: errors.ErrNotAStruct}, assert.True},
{errors.Required("", "foo"), assert.False},
{errors.Invalid("", "foo", "bar"), assert.False},
{errors.Parse("", "foo", errors.ErrNotExported), assert.False},
{errors.Wrap("", "foo", "bar", errors.ErrNotSettable, "qux"), assert.False},
}
for _, tc := range testCases {
tc.assert(t, confire.IsParseError(tc.err))
}
}