-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmethod_test.go
More file actions
34 lines (30 loc) · 819 Bytes
/
method_test.go
File metadata and controls
34 lines (30 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package fux
import (
"fmt"
"github.com/stretchr/testify/assert"
"io"
"net/http"
"net/http/httptest"
"testing"
)
func TestGet(t *testing.T) {
f := New()
f.Get("/test", func(w http.ResponseWriter, request *http.Request) {
Response(w).Status(http.StatusOK)
_, err := w.Write([]byte("test response"))
assert.Nil(t, err)
})
assertResponseBody := func(t *testing.T, s *httptest.Server, expectedResponse string) {
response, err := s.Client().Get(fmt.Sprintf("%s/test", s.URL))
assert.Nil(t, err)
assert.Equal(t, 200, response.StatusCode)
body, err := io.ReadAll(response.Body)
assert.Nil(t, err)
assert.Equal(t, expectedResponse, string(body))
}
t.Run("get request", func(t *testing.T) {
s := httptest.NewServer(f.Router)
defer s.Close()
assertResponseBody(t, s, "test response")
})
}