Skip to content

Commit

Permalink
Attempt to fix gin-gonic#1462 (gin-gonic#1463)
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkerou authored and appleboy committed Aug 12, 2018
1 parent 8fc8ce0 commit 7e64d32
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
20 changes: 20 additions & 0 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1560,6 +1560,26 @@ func TestContextRenderDataFromReader(t *testing.T) {
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) {
w := CreateTestResponseRecorder()
c, _ := CreateTestContext(w)
Expand Down
25 changes: 1 addition & 24 deletions test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

package gin

import (
"net/http"
"net/http/httptest"
)
import "net/http"

// CreateTestContext returns a fresh engine and context for testing purposes
func CreateTestContext(w http.ResponseWriter) (c *Context, r *Engine) {
Expand All @@ -17,23 +14,3 @@ 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),
}
}

0 comments on commit 7e64d32

Please sign in to comment.