1
0
mirror of https://github.com/labstack/echo.git synced 2024-12-24 20:14:31 +02:00

Increased coverage

This commit is contained in:
Marcin Tojek 2015-11-08 00:59:08 +01:00
parent 31b657e1d2
commit 52daa9ddc9

View File

@ -32,6 +32,8 @@ func TestContext(t *testing.T) {
userXML := `<user><id>1</id><name>Joe</name></user>` userXML := `<user><id>1</id><name>Joe</name></user>`
userXMLIndent := "_<user>\n_?<id>1</id>\n_?<name>Joe</name>\n_</user>" userXMLIndent := "_<user>\n_?<id>1</id>\n_?<name>Joe</name>\n_</user>"
var nonMarshallableChannel chan bool
req, _ := http.NewRequest(POST, "/", strings.NewReader(userJSON)) req, _ := http.NewRequest(POST, "/", strings.NewReader(userJSON))
rec := httptest.NewRecorder() rec := httptest.NewRecorder()
c := NewContext(req, NewResponse(rec), New()) c := NewContext(req, NewResponse(rec), New())
@ -99,6 +101,13 @@ func TestContext(t *testing.T) {
assert.Equal(t, userJSON, rec.Body.String()) 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 // JSONIndent
rec = httptest.NewRecorder() rec = httptest.NewRecorder()
c = NewContext(req, NewResponse(rec), New()) c = NewContext(req, NewResponse(rec), New())
@ -109,6 +118,12 @@ func TestContext(t *testing.T) {
assert.Equal(t, userJSONIndent, rec.Body.String()) 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 // JSONP
rec = httptest.NewRecorder() rec = httptest.NewRecorder()
c = NewContext(req, NewResponse(rec), New()) c = NewContext(req, NewResponse(rec), New())
@ -130,6 +145,12 @@ func TestContext(t *testing.T) {
assert.Equal(t, xml.Header+userXML, rec.Body.String()) 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 // XMLIndent
rec = httptest.NewRecorder() rec = httptest.NewRecorder()
c = NewContext(req, NewResponse(rec), New()) c = NewContext(req, NewResponse(rec), New())
@ -140,6 +161,12 @@ func TestContext(t *testing.T) {
assert.Equal(t, xml.Header+userXMLIndent, rec.Body.String()) 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 // String
rec = httptest.NewRecorder() rec = httptest.NewRecorder()
c = NewContext(req, NewResponse(rec), New()) c = NewContext(req, NewResponse(rec), New())