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
Signed by: apairon
GPG Key ID: 7270D06DDA7FE8C3
4 changed files with 89 additions and 3 deletions

5
.gitignore vendored
View File

@ -1,2 +1,3 @@
html/
build/dist
/html/
/build/dist
/coverage.out

View File

@ -6,7 +6,7 @@ workspace:
path: src/gitbase.de/apairon/mark2web
steps:
- name: build for linux
- name: test
image: golang:latest
environment:
CGO_ENABLED: 0
@ -15,6 +15,17 @@ steps:
commands:
- git submodule update --init --recursive
- git fetch --tags
- go test -v -coverprofile coverage.out ./pkg/*
when:
event: [ push, tag ]
- name: build for linux
image: golang:latest
environment:
CGO_ENABLED: 0
GOOS: linux
GOARCH: amd64
commands:
- scripts/build.sh
when:
event: [ push, tag ]

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, ``)
})
})
}