This commit is contained in:
parent
3c87da15e1
commit
5cc4b9d001
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
html/
|
/html/
|
||||||
build/dist
|
/build/dist
|
||||||
|
/coverage.out
|
||||||
|
@ -6,7 +6,7 @@ workspace:
|
|||||||
path: src/gitbase.de/apairon/mark2web
|
path: src/gitbase.de/apairon/mark2web
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: build for linux
|
- name: test
|
||||||
image: golang:latest
|
image: golang:latest
|
||||||
environment:
|
environment:
|
||||||
CGO_ENABLED: 0
|
CGO_ENABLED: 0
|
||||||
@ -15,6 +15,17 @@ steps:
|
|||||||
commands:
|
commands:
|
||||||
- git submodule update --init --recursive
|
- git submodule update --init --recursive
|
||||||
- git fetch --tags
|
- 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
|
- scripts/build.sh
|
||||||
when:
|
when:
|
||||||
event: [ push, tag ]
|
event: [ push, tag ]
|
||||||
|
24
pkg/filter/dump_test.go
Normal file
24
pkg/filter/dump_test.go
Normal 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
50
pkg/filter/json_test.go
Normal 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, ``)
|
||||||
|
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user