Adds basic unit testing

This commit is contained in:
2015-08-12 20:06:01 +02:00
parent 9a123c9281
commit 5ef16a7afc
2 changed files with 96 additions and 0 deletions

36
narco_test.go Normal file
View 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)
}