github.com/gotstago/buffalo@v0.9.5/wrappers_test.go (about)

     1  package buffalo
     2  
     3  import (
     4  	"net/http"
     5  	"testing"
     6  
     7  	"github.com/markbates/willie"
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  func Test_WrapHandlerFunc(t *testing.T) {
    12  	r := require.New(t)
    13  
    14  	a := New(Options{})
    15  	a.GET("/foo", WrapHandlerFunc(func(res http.ResponseWriter, req *http.Request) {
    16  		res.Write([]byte("hello"))
    17  	}))
    18  
    19  	w := willie.New(a)
    20  	res := w.Request("/foo").Get()
    21  
    22  	r.Equal("hello", res.Body.String())
    23  }
    24  
    25  func Test_WrapHandler(t *testing.T) {
    26  	r := require.New(t)
    27  
    28  	a := New(Options{})
    29  	a.GET("/foo", WrapHandler(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
    30  		res.Write([]byte("hello"))
    31  	})))
    32  
    33  	w := willie.New(a)
    34  	res := w.Request("/foo").Get()
    35  
    36  	r.Equal("hello", res.Body.String())
    37  }