(t *testing.T)
| 68 | } |
| 69 | |
| 70 | func TestFormat(t *testing.T) { |
| 71 | tt := testutils.T{t} |
| 72 | |
| 73 | baseErr := goErr.New("woo") |
| 74 | const woo = `woo` |
| 75 | const waawoo = `waa: woo` |
| 76 | testCases := []struct { |
| 77 | name string |
| 78 | err error |
| 79 | expFmtSimple string |
| 80 | expFmtVerbose string |
| 81 | }{ |
| 82 | {"keys", |
| 83 | telemetrykeys.WithTelemetry(baseErr, "a", "b"), |
| 84 | woo, ` |
| 85 | woo |
| 86 | (1) keys: [a b] |
| 87 | Wraps: (2) woo |
| 88 | Error types: (1) *telemetrykeys.withTelemetry (2) *errors.errorString`}, |
| 89 | |
| 90 | {"keys + wrapper", |
| 91 | telemetrykeys.WithTelemetry(&werrFmt{baseErr, "waa"}, "a", "b"), |
| 92 | waawoo, ` |
| 93 | waa: woo |
| 94 | (1) keys: [a b] |
| 95 | Wraps: (2) waa |
| 96 | | -- this is waa's |
| 97 | | multi-line payload |
| 98 | Wraps: (3) woo |
| 99 | Error types: (1) *telemetrykeys.withTelemetry (2) *telemetrykeys_test.werrFmt (3) *errors.errorString`}, |
| 100 | |
| 101 | {"wrapper + keys", |
| 102 | &werrFmt{telemetrykeys.WithTelemetry(baseErr, "a", "b"), "waa"}, |
| 103 | waawoo, ` |
| 104 | waa: woo |
| 105 | (1) waa |
| 106 | | -- this is waa's |
| 107 | | multi-line payload |
| 108 | Wraps: (2) keys: [a b] |
| 109 | Wraps: (3) woo |
| 110 | Error types: (1) *telemetrykeys_test.werrFmt (2) *telemetrykeys.withTelemetry (3) *errors.errorString`}, |
| 111 | } |
| 112 | |
| 113 | for _, test := range testCases { |
| 114 | tt.Run(test.name, func(tt testutils.T) { |
| 115 | err := test.err |
| 116 | |
| 117 | // %s is simple formatting |
| 118 | tt.CheckStringEqual(fmt.Sprintf("%s", err), test.expFmtSimple) |
| 119 | |
| 120 | // %v is simple formatting too, for compatibility with the past. |
| 121 | tt.CheckStringEqual(fmt.Sprintf("%v", err), test.expFmtSimple) |
| 122 | |
| 123 | // %q is always like %s but quotes the result. |
| 124 | ref := fmt.Sprintf("%q", test.expFmtSimple) |
| 125 | tt.CheckStringEqual(fmt.Sprintf("%q", err), ref) |
| 126 | |
| 127 | // %+v is the verbose mode. |
nothing calls this directly
no test coverage detected
searching dependent graphs…