added tests
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Sebastian Frank
2019-03-19 21:25:14 +01:00
parent 3c87da15e1
commit 5cc4b9d001
4 changed files with 89 additions and 3 deletions

24
pkg/filter/dump_test.go Normal file
View File

@@ -0,0 +1,24 @@
package filter
import (
"testing"
"github.com/davecgh/go-spew/spew"
"github.com/flosch/pongo2"
. "github.com/smartystreets/goconvey/convey"
)
func TestDumpFilter(t *testing.T) {
Convey("set context", t, func() {
ctx := pongo2.Context{
"testvar": "test",
}
Convey("parse template", func() {
output, err := pongo2.RenderTemplateString("{{ testvar|safe|dump }}", ctx)
So(err, ShouldBeNil)
So(output, ShouldEqual, spew.Sdump("test"))
})
})
}

50
pkg/filter/json_test.go Normal file
View File

@@ -0,0 +1,50 @@
package filter
import (
"math"
"testing"
"github.com/flosch/pongo2"
. "github.com/smartystreets/goconvey/convey"
)
func TestJSONFilter(t *testing.T) {
Convey("set context", t, func() {
ctx := pongo2.Context{
"teststr": "test",
"testmap": map[string]interface{}{
"float": 1.23,
"int": 5,
"str": "test",
},
"testerr": math.Inf(1),
}
Convey("parse template", func() {
output, err := pongo2.RenderTemplateString("{{ teststr|safe|json }}", ctx)
So(err, ShouldBeNil)
So(output, ShouldEqual, `"test"`)
output, err = pongo2.RenderTemplateString("{{ testmap|safe|json }}", ctx)
So(err, ShouldBeNil)
So(output, ShouldEqual, `{"float":1.23,"int":5,"str":"test"}`)
output, err = pongo2.RenderTemplateString(`{{ testmap|safe|json:"pretty" }}`, ctx)
So(err, ShouldBeNil)
So(output, ShouldEqual, `{
"float": 1.23,
"int": 5,
"str": "test"
}`)
output, err = pongo2.RenderTemplateString("{{ testnil|safe|json }}", ctx)
So(err, ShouldBeNil)
So(output, ShouldEqual, `null`)
output, err = pongo2.RenderTemplateString("{{ testerr|safe|json }}", ctx)
So(err, ShouldNotBeNil)
So(output, ShouldEqual, ``)
})
})
}