| 99 | } |
| 100 | |
| 101 | func TestData(t *testing.T) { |
| 102 | root := errors.New("foo") |
| 103 | cases := []struct { |
| 104 | err error |
| 105 | data interface{} |
| 106 | }{ |
| 107 | {WithData(root, "a", "b"), map[string]interface{}{"a": "b"}}, |
| 108 | {WithData(WithData(root, "a", "b"), "c", "d"), map[string]interface{}{"a": "b", "c": "d"}}, |
| 109 | {Wrap(WithData(root, "a", "b"), "baz"), map[string]interface{}{"a": "b"}}, |
| 110 | } |
| 111 | |
| 112 | for _, test := range cases { |
| 113 | if got := Data(test.err); !reflect.DeepEqual(got, test.data) { |
| 114 | t.Errorf("Data(%#v) = %v want %v", test.err, got, test.data) |
| 115 | } |
| 116 | if got := Root(test.err); got != root { |
| 117 | t.Errorf("Root(%#v) = %v want %v", test.err, got, root) |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | func TestSub(t *testing.T) { |
| 123 | x := errors.New("x") |