From 66d56396cad01fbaf37fd62c66f8d1e66253c0f0 Mon Sep 17 00:00:00 2001 From: John Guo Date: Thu, 18 Nov 2021 22:16:54 +0800 Subject: [PATCH] improve unit testing case for package gview --- os/gview/gview_z_unit_test.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/os/gview/gview_z_unit_test.go b/os/gview/gview_z_unit_test.go index c055d3fde..f81a38700 100644 --- a/os/gview/gview_z_unit_test.go +++ b/os/gview/gview_z_unit_test.go @@ -216,15 +216,19 @@ func Test_FuncNl2Br(t *testing.T) { func Test_FuncInclude(t *testing.T) { gtest.C(t, func(t *gtest.T) { - header := `

HEADER

` - main := `

hello gf

` - footer := `

FOOTER

` - layout := `{{include "header.html" .}} + var ( + header = `

HEADER

` + main = `

hello gf

` + footer = `

FOOTER

` + layout = `{{include "header.html" .}} {{include "main.html" .}} {{include "footer.html" .}}` - templatePath := gfile.Pwd() + gfile.Separator + "template" + templatePath = gfile.Pwd() + gfile.Separator + "template" + ) + gfile.Mkdir(templatePath) defer gfile.Remove(templatePath) + // headerFile, _ := gfile.Create(templatePath + gfile.Separator + "header.html") err := ioutil.WriteFile(templatePath+gfile.Separator+"header.html", []byte(header), 0644) if err != nil { @@ -235,19 +239,21 @@ func Test_FuncInclude(t *testing.T) { ioutil.WriteFile(templatePath+gfile.Separator+"layout.html", []byte(layout), 0644) view := gview.New(templatePath) result, err := view.Parse(context.TODO(), "notfound.html") - t.Assert(err != nil, true) + t.AssertNE(err, nil) t.Assert(result, ``) + result, err = view.Parse(context.TODO(), "layout.html") - t.Assert(err != nil, false) + t.AssertNil(err) t.Assert(result, `

HEADER

hello gf

FOOTER

`) + notfoundPath := templatePath + gfile.Separator + "template" + gfile.Separator + "notfound.html" gfile.Mkdir(templatePath + gfile.Separator + "template") gfile.Create(notfoundPath) ioutil.WriteFile(notfoundPath, []byte("notfound"), 0644) result, err = view.Parse(context.TODO(), "notfound.html") - t.Assert(err != nil, true) + t.AssertNE(err, nil) t.Assert(result, ``) }) }