github.com/segakazzz/buffalo@v0.16.22-0.20210119082501-1f52048d3feb/render/func_test.go (about)

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