(t *testing.T)
| 40 | } |
| 41 | |
| 42 | func TestArrayErrorMarshalFunc(t *testing.T) { |
| 43 | prefixed := func(s, prefix string) string { |
| 44 | if s == "null" { |
| 45 | return "" |
| 46 | } |
| 47 | return prefix + s + `,` |
| 48 | } |
| 49 | errs := []error{ |
| 50 | nil, |
| 51 | fmt.Errorf("failure"), |
| 52 | loggableError{fmt.Errorf("whoops")}, |
| 53 | nonLoggableError{fmt.Errorf("oops"), 402}, |
| 54 | } |
| 55 | type testCase struct { |
| 56 | name string |
| 57 | marshal func(err error) interface{} |
| 58 | want []string |
| 59 | } |
| 60 | testCases := []testCase{ |
| 61 | { |
| 62 | name: "default", |
| 63 | marshal: nil, |
| 64 | want: []string{`null`, `"failure"`, `{"l":"WHOOPS"}`, `"oops"`}, |
| 65 | }, |
| 66 | { |
| 67 | name: "string", |
| 68 | marshal: func(err error) interface{} { |
| 69 | if err == nil { |
| 70 | return nil |
| 71 | } |
| 72 | return err.Error() |
| 73 | }, |
| 74 | want: []string{`null`, `"failure"`, `"whoops"`, `"oops"`}, |
| 75 | }, |
| 76 | { |
| 77 | name: "loggable", |
| 78 | marshal: func(err error) interface{} { |
| 79 | if err == nil { |
| 80 | return nil |
| 81 | } |
| 82 | return loggableError{err} |
| 83 | }, |
| 84 | want: []string{`null`, `{"l":"FAILURE"}`, `{"l":"WHOOPS"}`, `{"l":"OOPS"}`}, |
| 85 | }, |
| 86 | { |
| 87 | name: "non-loggable", |
| 88 | marshal: func(err error) interface{} { |
| 89 | if err == nil { |
| 90 | return nil |
| 91 | } |
| 92 | return nonLoggableError{err, 404} |
| 93 | }, |
| 94 | want: []string{`null`, `"failure"`, `"whoops"`, `"oops"`}, |
| 95 | }, |
| 96 | { |
| 97 | name: "interface", |
| 98 | marshal: func(err error) interface{} { |
| 99 | var some interfaceError |
nothing calls this directly
no test coverage detected