github.com/sohaha/zlsgo@v1.7.13-0.20240501141223-10dd1a906f76/znet/template_go_test.go (about)

     1  package znet
     2  
     3  import (
     4  	"bytes"
     5  	"testing"
     6  
     7  	"github.com/sohaha/zlsgo"
     8  	"github.com/sohaha/zlsgo/zstring"
     9  )
    10  
    11  func TestHTMLRender(t *testing.T) {
    12  	tt := zlsgo.NewTest(t)
    13  
    14  	engine := newGoTemplate(nil, "./testdata/html")
    15  
    16  	err := engine.Load()
    17  	tt.NoError(err)
    18  
    19  	var buf bytes.Buffer
    20  	err = engine.Render(&buf, "index", map[string]interface{}{
    21  		"Title": "Hello, World!",
    22  	})
    23  	tt.NoError(err)
    24  	expect := `<h2>Header</h2><h1>Hello, World!</h1><h2>Footer</h2>`
    25  	tt.Equal(expect, zstring.TrimLine(buf.String()))
    26  }