-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrite_path_test.go
72 lines (67 loc) · 1.43 KB
/
write_path_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
package errpath_test
import (
"errors"
"testing"
"github.com/MarkRosemaker/errpath"
)
var testErr = errors.New("a test error")
func TestPath(t *testing.T) {
err := &errpath.ErrField{
Field: "foo",
Err: &errpath.ErrField{
Field: "bar",
Err: &errpath.ErrKey{
Key: "baz",
Err: &errpath.ErrField{
Field: "qux",
Err: &errpath.ErrIndex{
Index: 3,
Err: &errpath.ErrField{
Field: "quux",
Err: &errpath.ErrInvalid[string]{
Value: "corge",
},
},
},
},
},
},
}
if want := `foo.bar["baz"].qux[3].quux ("corge") is invalid`; err.Error() != want {
t.Fatalf("want: %s, got: %s", want, err.Error())
}
}
func TestPath_join(t *testing.T) {
err := &errpath.ErrField{
Field: "foo",
Err: &errpath.ErrKey{
Key: "bar",
Err: errors.Join(
&errpath.ErrIndex{
Index: 3,
Err: &errpath.ErrField{
Field: "name",
Err: &errpath.ErrInvalid[string]{
Value: "corge",
Message: "duplicate name",
},
},
},
&errpath.ErrIndex{
Index: 5,
Err: &errpath.ErrField{
Field: "name",
Err: &errpath.ErrInvalid[string]{
Value: "corge",
Message: "duplicate name",
},
},
},
),
},
}
if want := `foo["bar"][3].name ("corge") is invalid: duplicate name
foo["bar"][5].name ("corge") is invalid: duplicate name`; err.Error() != want {
t.Fatalf("want: %s, got: %s", want, err.Error())
}
}