diff options
author | Ben Morrison <ben@gbmor.dev> | 2019-05-21 17:11:56 -0400 |
---|---|---|
committer | Ben Morrison <ben@gbmor.dev> | 2019-05-21 17:11:56 -0400 |
commit | a28407d3a25df1841ee43b0d3ceaaa67cf4e97ab (patch) | |
tree | d504e3b90f47a4a3570e1aae5e3fa510fe896ea3 | |
parent | d083ce6beaa5268848fe61f1b9a81ad8914f0bd2 (diff) | |
download | getwtxt-a28407d3a25df1841ee43b0d3ceaaa67cf4e97ab.tar.gz |
testing http related funcs
-rw-r--r-- | http_test.go | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/http_test.go b/http_test.go new file mode 100644 index 0000000..67ccc88 --- /dev/null +++ b/http_test.go @@ -0,0 +1,47 @@ +package main + +import ( + "errors" + "net/http" + "net/http/httptest" + "testing" +) + +func Test_log400(t *testing.T) { + initTestConf() + t.Run("log400", func(t *testing.T) { + w := httptest.NewRecorder() + req := httptest.NewRequest("POST", "/400", nil) + log400(w, req, errors.New("400 Test")) + resp := w.Result() + if resp.StatusCode != http.StatusBadRequest { + t.Errorf("Didn't receive 400, received: %v\n", resp.StatusCode) + } + }) +} + +func Test_log404(t *testing.T) { + initTestConf() + t.Run("log404", func(t *testing.T) { + w := httptest.NewRecorder() + req := httptest.NewRequest("GET", "/404", nil) + log404(w, req, errors.New("404 Test")) + resp := w.Result() + if resp.StatusCode != http.StatusNotFound { + t.Errorf("Didn't receive 404, received: %v\n", resp.StatusCode) + } + }) +} + +func Test_log500(t *testing.T) { + initTestConf() + t.Run("log500", func(t *testing.T) { + w := httptest.NewRecorder() + req := httptest.NewRequest("POST", "/500", nil) + log500(w, req, errors.New("500 Test")) + resp := w.Result() + if resp.StatusCode != http.StatusInternalServerError { + t.Errorf("Didn't receive 500, received: %v\n", resp.StatusCode) + } + }) +} |