Add tests for context.Stream (#1433)

This commit is contained in:
Dmitry Dorogin
2018-08-07 01:44:32 +03:00
committed by Bo-Yi Wu
parent e2b4cf6e2d
commit 9b7e7bdce6
2 changed files with 57 additions and 0 deletions
+21
View File
@@ -6,6 +6,7 @@ package gin
import (
"net/http"
"net/http/httptest"
)
// CreateTestContext returns a fresh engine and context for testing purposes
@@ -16,3 +17,23 @@ func CreateTestContext(w http.ResponseWriter) (c *Context, r *Engine) {
c.writermem.reset(w)
return
}
type TestResponseRecorder struct {
*httptest.ResponseRecorder
closeChannel chan bool
}
func (r *TestResponseRecorder) CloseNotify() <-chan bool {
return r.closeChannel
}
func (r *TestResponseRecorder) closeClient() {
r.closeChannel <- true
}
func CreateTestResponseRecorder() *TestResponseRecorder {
return &TestResponseRecorder{
httptest.NewRecorder(),
make(chan bool, 1),
}
}