add test cases for YAML

This commit is contained in:
thinkerou 2017-11-18 09:24:14 +08:00
parent a94da2a7b7
commit dc56b1a1bb

View File

@ -7,6 +7,7 @@ package render
import ( import (
"bytes" "bytes"
"encoding/xml" "encoding/xml"
"errors"
"html/template" "html/template"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
@ -170,6 +171,19 @@ b:
assert.Equal(t, w.Header().Get("Content-Type"), "application/x-yaml; charset=utf-8") assert.Equal(t, w.Header().Get("Content-Type"), "application/x-yaml; charset=utf-8")
} }
type fail struct{}
// Hook MarshalYAML
func (ft *fail) MarshalYAML() (interface{}, error) {
return nil, errors.New("fail")
}
func TestRenderYAMLFail(t *testing.T) {
w := httptest.NewRecorder()
err := (YAML{&fail{}}).Render(w)
assert.Error(t, err)
}
func TestRenderXML(t *testing.T) { func TestRenderXML(t *testing.T) {
w := httptest.NewRecorder() w := httptest.NewRecorder()
data := xmlmap{ data := xmlmap{