github.com/sotirispl/buffalo@v0.11.1/render/func_test.go (about) 1 package render_test 2 3 import ( 4 "bytes" 5 "io" 6 "testing" 7 8 "github.com/gobuffalo/buffalo/render" 9 "github.com/stretchr/testify/require" 10 ) 11 12 func Test_Func(t *testing.T) { 13 r := require.New(t) 14 15 type ji func(string, render.RendererFunc) render.Renderer 16 17 table := []ji{ 18 render.Func, 19 render.New(render.Options{}).Func, 20 } 21 22 for _, j := range table { 23 bb := &bytes.Buffer{} 24 re := j("foo/bar", func(w io.Writer, data render.Data) error { 25 _, err := w.Write([]byte(data["name"].(string))) 26 return err 27 }) 28 29 r.Equal("foo/bar", re.ContentType()) 30 err := re.Render(bb, render.Data{"name": "Mark"}) 31 r.NoError(err) 32 r.Equal("Mark", bb.String()) 33 } 34 }