(t *testing.T)
| 25 | ) |
| 26 | |
| 27 | func TestHTTP(t *testing.T) { |
| 28 | err := fmt.Errorf("hello") |
| 29 | err = exthttp.WrapWithHTTPCode(err, 302) |
| 30 | |
| 31 | // Simulate a network transfer. |
| 32 | enc := errors.EncodeError(context.Background(), err) |
| 33 | otherErr := errors.DecodeError(context.Background(), enc) |
| 34 | |
| 35 | tt := testutils.T{T: t} |
| 36 | |
| 37 | // Error is preserved through the network. |
| 38 | tt.CheckDeepEqual(otherErr, err) |
| 39 | |
| 40 | // It's possible to extract the HTTP code. |
| 41 | tt.CheckEqual(exthttp.GetHTTPCode(otherErr, 100), 302) |
| 42 | |
| 43 | // If there are multiple codes, the most recent one wins. |
| 44 | otherErr = exthttp.WrapWithHTTPCode(otherErr, 404) |
| 45 | tt.CheckEqual(exthttp.GetHTTPCode(otherErr, 100), 404) |
| 46 | |
| 47 | // The code is hidden when the error is printed with %v. |
| 48 | tt.CheckStringEqual(fmt.Sprintf("%v", err), `hello`) |
| 49 | // The code appears when the error is printed verbosely. |
| 50 | tt.CheckStringEqual(fmt.Sprintf("%+v", err), `hello |
| 51 | (1) http code: 302 |
| 52 | Wraps: (2) hello |
| 53 | Error types: (1) *exthttp.withHTTPCode (2) *errors.errorString`) |
| 54 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…