mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-16 21:32:11 +08:00
Fix unhandled merge conflict in context_test.go
This commit is contained in:
parent
2f166fe9cc
commit
4a99873e23
@ -7,6 +7,7 @@ package gin
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
@ -381,6 +382,35 @@ func TestContextGetCookie(t *testing.T) {
|
||||
assert.Equal(t, cookie, "gin")
|
||||
}
|
||||
|
||||
func TestContextBodyAllowedForStatus(t *testing.T) {
|
||||
assert.Equal(t, false, bodyAllowedForStatus(102))
|
||||
assert.Equal(t, false, bodyAllowedForStatus(204))
|
||||
assert.Equal(t, false, bodyAllowedForStatus(304))
|
||||
assert.Equal(t, true, bodyAllowedForStatus(500))
|
||||
}
|
||||
|
||||
type TestPanicRender struct {
|
||||
}
|
||||
|
||||
func (*TestPanicRender) Render(http.ResponseWriter) error {
|
||||
return errors.New("TestPanicRender")
|
||||
}
|
||||
|
||||
func (*TestPanicRender) WriteContentType(http.ResponseWriter) {}
|
||||
|
||||
func TestContextRenderPanicIfErr(t *testing.T) {
|
||||
defer func() {
|
||||
r := recover()
|
||||
assert.Equal(t, "TestPanicRender", fmt.Sprint(r))
|
||||
}()
|
||||
w := httptest.NewRecorder()
|
||||
c, _ := CreateTestContext(w)
|
||||
|
||||
c.Render(http.StatusOK, &TestPanicRender{})
|
||||
|
||||
assert.Fail(t, "Panic not detected")
|
||||
}
|
||||
|
||||
// Tests that the response is serialized as JSON
|
||||
// and Content-Type is set to application/json
|
||||
func TestContextRenderJSON(t *testing.T) {
|
||||
|
@ -34,7 +34,12 @@ func (r JSON) WriteContentType(w http.ResponseWriter) {
|
||||
|
||||
func WriteJSON(w http.ResponseWriter, obj interface{}) error {
|
||||
writeContentType(w, jsonContentType)
|
||||
return json.NewEncoder(w).Encode(obj)
|
||||
jsonBytes, err := json.Marshal(obj)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
w.Write(jsonBytes)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r IndentedJSON) Render(w http.ResponseWriter) error {
|
||||
|
Loading…
x
Reference in New Issue
Block a user