Last active
November 20, 2020 11:47
-
-
Save antklim/59abd3b3d3526a0044f547a0b93546b7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func TestNotFoundHandler(t *testing.T) { | |
| req := httptest.NewRequest("GET", "/not-found", nil) | |
| rr := httptest.NewRecorder() | |
| notFoundHandler(rr, req) | |
| res := rr.Result() | |
| resBody, _ := ioutil.ReadAll(res.Body) | |
| assert.Equal(t, http.StatusNotFound, res.StatusCode) | |
| assert.JSONEq(t, `{"message": "not found"}`, string(resBody)) | |
| } | |
| func TestDoHandler(t *testing.T) { | |
| req := httptest.NewRequest( | |
| "POST", | |
| "/do", | |
| strings.NewReader(`{"operation": "add", "arguments": [1,2]}`)) | |
| rr := httptest.NewRecorder() | |
| doHandler()(rr, req) | |
| res := rr.Result() | |
| resBody, _ := ioutil.ReadAll(res.Body) | |
| assert.Equal(t, http.StatusOK, res.StatusCode) | |
| assert.JSONEq( | |
| t, | |
| `{"operation": "add", "arguments": [1,2], "result": 3}`, | |
| string(resBody)) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment