parent
8fc8ce0472
commit
7e64d32269
@ -1560,6 +1560,26 @@ func TestContextRenderDataFromReader(t *testing.T) {
|
|||||||
assert.Equal(t, extraHeaders["Content-Disposition"], w.HeaderMap.Get("Content-Disposition"))
|
assert.Equal(t, extraHeaders["Content-Disposition"], w.HeaderMap.Get("Content-Disposition"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestContextStream(t *testing.T) {
|
func TestContextStream(t *testing.T) {
|
||||||
w := CreateTestResponseRecorder()
|
w := CreateTestResponseRecorder()
|
||||||
c, _ := CreateTestContext(w)
|
c, _ := CreateTestContext(w)
|
||||||
|
@ -4,10 +4,7 @@
|
|||||||
|
|
||||||
package gin
|
package gin
|
||||||
|
|
||||||
import (
|
import "net/http"
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
|
||||||
)
|
|
||||||
|
|
||||||
// CreateTestContext returns a fresh engine and context for testing purposes
|
// CreateTestContext returns a fresh engine and context for testing purposes
|
||||||
func CreateTestContext(w http.ResponseWriter) (c *Context, r *Engine) {
|
func CreateTestContext(w http.ResponseWriter) (c *Context, r *Engine) {
|
||||||
@ -17,23 +14,3 @@ func CreateTestContext(w http.ResponseWriter) (c *Context, r *Engine) {
|
|||||||
c.writermem.reset(w)
|
c.writermem.reset(w)
|
||||||
return
|
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),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user