-
Notifications
You must be signed in to change notification settings - Fork 16
/
group_test.go
35 lines (30 loc) · 681 Bytes
/
group_test.go
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
35
package ngamux
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/golang-must/must"
)
func TestGroup(t *testing.T) {
must := must.New(t)
mux := New(
WithLogLevel(LogLevelQuiet),
)
handler := func(rw http.ResponseWriter, r *http.Request) error {
return Res(rw).Text("ok")
}
a := mux.Group("/a")
a.Get("", handler)
a.Post("", handler)
a.Put("", handler)
a.Patch("", handler)
a.Delete("", handler)
a.All("", handler)
rec := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, "/a", nil)
mux.ServeHTTP(rec, req)
result := strings.ReplaceAll(rec.Body.String(), "\n", "")
expected := "ok"
must.Equal(expected, result)
}