Adds basic unit testing
This commit is contained in:
36
narco_test.go
Normal file
36
narco_test.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package narco
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/codemodus/chain"
|
||||
"golang.org/x/net/context"
|
||||
. "gopkg.in/check.v1"
|
||||
)
|
||||
|
||||
type NarcoSuite struct {
|
||||
chain chain.Chain
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
func Test(t *testing.T) { TestingT(t) }
|
||||
|
||||
func NewNarcoSuite() *NarcoSuite {
|
||||
ctx := context.Background()
|
||||
return &NarcoSuite{
|
||||
ctx: ctx,
|
||||
chain: chain.New(),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *NarcoSuite) ServeHTTP(rec *httptest.ResponseRecorder, req *http.Request, handlerfunc http.HandlerFunc) {
|
||||
s.chain.EndFn(func(ctx context.Context, rw http.ResponseWriter, req *http.Request) {
|
||||
handlerfunc.ServeHTTP(rw, req)
|
||||
}).ServeHTTP(rec, req)
|
||||
}
|
||||
|
||||
func (s *NarcoSuite) ServeHTTPContext(rec *httptest.ResponseRecorder, req *http.Request, handlerfunc chain.HandlerFunc) {
|
||||
s.chain.EndFn(handlerfunc).ServeHTTP(rec, req)
|
||||
}
|
||||
Reference in New Issue
Block a user