mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-24 02:32:17 +08:00
add test cases for YAML
This commit is contained in:
parent
a94da2a7b7
commit
dc56b1a1bb
@ -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{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user