ch14.4
This commit is contained in:
@@ -1,33 +1,20 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"gitea.local.lab/Lbenedar/snippetbox/internal/assert"
|
||||
)
|
||||
|
||||
func TestPing(t *testing.T) {
|
||||
rr := httptest.NewRecorder()
|
||||
app := newTestApplication(t)
|
||||
|
||||
r, err := http.NewRequest(http.MethodGet, "/", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ts := newTestServer(t, app.routes())
|
||||
defer ts.Close()
|
||||
|
||||
ping(rr, r)
|
||||
statusCode, _, body := ts.get(t, "/ping")
|
||||
|
||||
rs := rr.Result()
|
||||
|
||||
assert.Equal(t, rs.StatusCode, http.StatusOK)
|
||||
defer rs.Body.Close()
|
||||
body, err := io.ReadAll(rs.Body)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
bytes.TrimSpace(body)
|
||||
assert.Equal(t, string(body), "OK")
|
||||
assert.Equal(t, statusCode, http.StatusOK)
|
||||
assert.Equal(t, body, "OK")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user