mirror of
https://github.com/labstack/echo.git
synced 2024-12-24 20:14:31 +02:00
Increased coverage
This commit is contained in:
parent
31b657e1d2
commit
52daa9ddc9
@ -32,6 +32,8 @@ func TestContext(t *testing.T) {
|
||||
userXML := `<user><id>1</id><name>Joe</name></user>`
|
||||
userXMLIndent := "_<user>\n_?<id>1</id>\n_?<name>Joe</name>\n_</user>"
|
||||
|
||||
var nonMarshallableChannel chan bool
|
||||
|
||||
req, _ := http.NewRequest(POST, "/", strings.NewReader(userJSON))
|
||||
rec := httptest.NewRecorder()
|
||||
c := NewContext(req, NewResponse(rec), New())
|
||||
@ -99,6 +101,13 @@ func TestContext(t *testing.T) {
|
||||
assert.Equal(t, userJSON, rec.Body.String())
|
||||
}
|
||||
|
||||
// JSON (error)
|
||||
rec = httptest.NewRecorder()
|
||||
c = NewContext(req, NewResponse(rec), New())
|
||||
val := make(chan bool)
|
||||
err = c.JSON(http.StatusOK, val)
|
||||
assert.Error(t, err)
|
||||
|
||||
// JSONIndent
|
||||
rec = httptest.NewRecorder()
|
||||
c = NewContext(req, NewResponse(rec), New())
|
||||
@ -109,6 +118,12 @@ func TestContext(t *testing.T) {
|
||||
assert.Equal(t, userJSONIndent, rec.Body.String())
|
||||
}
|
||||
|
||||
// JSONIndent (error)
|
||||
rec = httptest.NewRecorder()
|
||||
c = NewContext(req, NewResponse(rec), New())
|
||||
err = c.JSONIndent(http.StatusOK, nonMarshallableChannel, "_", "?")
|
||||
assert.Error(t, err)
|
||||
|
||||
// JSONP
|
||||
rec = httptest.NewRecorder()
|
||||
c = NewContext(req, NewResponse(rec), New())
|
||||
@ -130,6 +145,12 @@ func TestContext(t *testing.T) {
|
||||
assert.Equal(t, xml.Header+userXML, rec.Body.String())
|
||||
}
|
||||
|
||||
// XML (error)
|
||||
rec = httptest.NewRecorder()
|
||||
c = NewContext(req, NewResponse(rec), New())
|
||||
err = c.XML(http.StatusOK, nonMarshallableChannel)
|
||||
assert.Error(t, err)
|
||||
|
||||
// XMLIndent
|
||||
rec = httptest.NewRecorder()
|
||||
c = NewContext(req, NewResponse(rec), New())
|
||||
@ -140,6 +161,12 @@ func TestContext(t *testing.T) {
|
||||
assert.Equal(t, xml.Header+userXMLIndent, rec.Body.String())
|
||||
}
|
||||
|
||||
// XMLIndent (error)
|
||||
rec = httptest.NewRecorder()
|
||||
c = NewContext(req, NewResponse(rec), New())
|
||||
err = c.XMLIndent(http.StatusOK, nonMarshallableChannel, "_", "?")
|
||||
assert.Error(t, err)
|
||||
|
||||
// String
|
||||
rec = httptest.NewRecorder()
|
||||
c = NewContext(req, NewResponse(rec), New())
|
||||
|
Loading…
Reference in New Issue
Block a user