github.com/bketelsen/buffalo@v0.9.5/render/xml_test.go (about)

     1  package render_test
     2  
     3  import (
     4  	"bytes"
     5  	"strings"
     6  	"testing"
     7  
     8  	"github.com/gobuffalo/buffalo/render"
     9  	"github.com/stretchr/testify/require"
    10  )
    11  
    12  func Test_XML(t *testing.T) {
    13  	r := require.New(t)
    14  
    15  	type ji func(v interface{}) render.Renderer
    16  
    17  	table := []ji{
    18  		render.XML,
    19  		render.New(render.Options{}).XML,
    20  	}
    21  
    22  	type user struct {
    23  		Name string
    24  	}
    25  
    26  	for _, j := range table {
    27  		re := j(user{Name: "mark"})
    28  		r.Equal("application/xml", re.ContentType())
    29  		bb := &bytes.Buffer{}
    30  		err := re.Render(bb, nil)
    31  		r.NoError(err)
    32  		r.Equal("<user>\n  <Name>mark</Name>\n</user>", strings.TrimSpace(bb.String()))
    33  	}
    34  }