1
0
mirror of https://github.com/danog/gojekyll.git synced 2025-01-23 06:51:25 +01:00
gojekyll/pages/page_test.go

40 lines
1.4 KiB
Go
Raw Normal View History

2017-07-04 17:36:06 -04:00
package pages
import (
"bytes"
"io"
"testing"
2017-07-06 19:31:36 -04:00
"github.com/osteele/gojekyll/config"
2017-07-04 17:36:06 -04:00
"github.com/osteele/gojekyll/pipelines"
"github.com/stretchr/testify/require"
)
2017-07-06 19:31:36 -04:00
type renderingContextFake struct {
t *testing.T
cfg config.Config
}
2017-07-04 17:36:06 -04:00
2017-07-06 19:31:36 -04:00
func (c renderingContextFake) RenderingPipeline() pipelines.PipelineInterface { return c }
func (c renderingContextFake) Config() config.Config { return c.cfg }
func (c renderingContextFake) PathPrefix() string { return "." }
func (c renderingContextFake) OutputExt(string) string { return ".html" }
func (c renderingContextFake) Site() interface{} { return nil }
func (c renderingContextFake) ApplyLayout(layout string, src []byte, vars map[string]interface{}) ([]byte, error) {
2017-07-04 17:36:06 -04:00
require.Equal(c.t, "layout1", layout)
return nil, nil
}
2017-07-06 19:31:36 -04:00
func (c renderingContextFake) Render(w io.Writer, src []byte, filename string, vars map[string]interface{}) ([]byte, error) {
2017-07-04 17:36:06 -04:00
require.Equal(c.t, "testdata/page_with_layout.md", filename)
return nil, nil
}
func TestPageWrite(t *testing.T) {
2017-07-06 19:31:36 -04:00
cfg := config.Default()
p, err := NewFile("testdata/page_with_layout.md", containerFake{cfg, ""}, "page_with_layout.md", map[string]interface{}{})
2017-07-04 17:36:06 -04:00
require.NoError(t, err)
require.NotNil(t, p)
buf := new(bytes.Buffer)
2017-07-06 19:31:36 -04:00
require.NoError(t, p.Write(buf, renderingContextFake{t, cfg}))
2017-07-04 17:36:06 -04:00
}