1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-11-26 21:04:39 +01:00
gojekyll/pages/file_test.go

46 lines
1.2 KiB
Go
Raw Normal View History

2017-07-03 15:37:14 +02:00
package pages
import (
2017-08-22 16:47:34 +02:00
"bytes"
"fmt"
2017-07-10 19:23:51 +02:00
"io"
2017-07-03 15:37:14 +02:00
"testing"
"github.com/danog/gojekyll/config"
"github.com/danog/gojekyll/renderers"
"github.com/danog/liquid"
2017-07-03 15:37:14 +02:00
"github.com/stretchr/testify/require"
)
2017-07-10 19:23:51 +02:00
type siteFake struct {
t *testing.T
cfg config.Config
2017-07-03 15:37:14 +02:00
}
2017-08-18 17:07:01 +02:00
func (s siteFake) Config() *config.Config { return &s.cfg }
func (s siteFake) RelativePath(p string) string { return p }
func (s siteFake) RendererManager() renderers.Renderers { return &renderManagerFake{s.t} }
2017-07-03 15:37:14 +02:00
2017-08-18 17:07:01 +02:00
type renderManagerFake struct{ t *testing.T }
2017-07-10 19:23:51 +02:00
2017-08-22 16:47:34 +02:00
func (rm renderManagerFake) ApplyLayout(layout string, content []byte, vars liquid.Bindings) ([]byte, error) {
require.Equal(rm.t, "layout1", layout)
2017-08-22 16:47:34 +02:00
return content, nil
2017-07-10 19:23:51 +02:00
}
2017-08-22 16:47:34 +02:00
func (rm renderManagerFake) Render(w io.Writer, src []byte, vars liquid.Bindings, filename string, lineNo int) error {
2017-08-22 16:47:34 +02:00
if bytes.Contains(src, []byte("{% error %}")) {
return fmt.Errorf("render error")
}
2017-08-10 16:44:04 +02:00
_, err := io.WriteString(w, "rendered: ")
if err != nil {
return err
}
_, err = w.Write(src)
2017-08-10 15:06:53 +02:00
return err
2017-07-10 19:23:51 +02:00
}
2017-08-10 16:44:04 +02:00
func (rm renderManagerFake) RenderTemplate(src []byte, vars liquid.Bindings, filename string, lineNo int) ([]byte, error) {
2017-08-10 16:44:04 +02:00
return append([]byte("rendered: "), src...), nil
}