github.com/sotirispl/buffalo@v0.11.1/render/json_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_JSON(t *testing.T) { 13 r := require.New(t) 14 15 type ji func(v interface{}) render.Renderer 16 17 table := []ji{ 18 render.JSON, 19 render.New(render.Options{}).JSON, 20 } 21 22 for _, j := range table { 23 re := j(map[string]string{"hello": "world"}) 24 r.Equal("application/json", re.ContentType()) 25 bb := &bytes.Buffer{} 26 err := re.Render(bb, nil) 27 r.NoError(err) 28 r.Equal(`{"hello":"world"}`, strings.TrimSpace(bb.String())) 29 } 30 }