This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
errors_test.go
67 lines (58 loc) · 1.5 KB
/
errors_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
package pointerstructure
import (
"errors"
"testing"
)
var structure interface{} = map[string]interface{}{
"foo": map[string]interface{}{
"bar": map[string]interface{}{
"baz": []int{3, 0, 1, 5},
},
"quxx": "test",
},
}
const (
unparsable = "foo/bar"
notFound = "/foo/baz/bar"
outOfRange = "/foo/bar/baz/5"
cantConvert = "/foo/bar/baz/-"
invalidKind = "/foo/quxx/test"
)
func TestErrParse(t *testing.T) {
_, err := Parse(unparsable)
if !errors.Is(err, ErrParse) {
t.Fatalf("expected ErrParse in the error chain, but it was not")
}
}
func TestErrNotFound(t *testing.T) {
_, err := Get(structure, notFound)
if !errors.Is(err, ErrNotFound) {
t.Fatalf("expected ErrNotFound in the error chain, but it was not")
}
}
func TestErrNotFound_structKey(t *testing.T) {
_, err := Get(struct {
Nope string
}{}, notFound)
if !errors.Is(err, ErrNotFound) {
t.Fatalf("expected ErrNotFound in the error chain, but it was not")
}
}
func TestErrOutOfRange(t *testing.T) {
_, err := Get(structure, outOfRange)
if !errors.Is(err, ErrOutOfRange) {
t.Fatalf("expected ErrOutOfRange in the error chain, but it was not")
}
}
func TestErrConvert(t *testing.T) {
_, err := Set(structure, cantConvert, "test")
if !errors.Is(err, ErrConvert) {
t.Fatalf("expected ErrConvert in the error chain, but it was not")
}
}
func TestErrInvalidKind(t *testing.T) {
_, err := Get(structure, invalidKind)
if !errors.Is(err, ErrInvalidKind) {
t.Fatalf("expected ErrInvalidKind in the error chain, but it was not")
}
}