1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-11-27 15:34:39 +01:00
gojekyll/collection/collection_test.go
2017-07-10 14:14:42 -04:00

58 lines
1.8 KiB
Go

package collection
import (
"testing"
"github.com/osteele/gojekyll/config"
"github.com/osteele/gojekyll/pipelines"
"github.com/stretchr/testify/require"
)
type siteMock struct{ c config.Config }
func (c siteMock) Config() *config.Config { return &c.c }
func (c siteMock) Exclude(string) bool { return false }
func (c siteMock) OutputExt(s string) string { return "" }
func (c siteMock) RenderingPipeline() pipelines.PipelineInterface { panic("unimplemented") }
func TestNewCollection(t *testing.T) {
site := siteMock{config.Default()}
c1 := New(site, "c", map[string]interface{}{"output": true})
require.Equal(t, true, c1.Output())
require.Equal(t, "_c/", c1.PathPrefix())
c2 := New(site, "c", map[string]interface{}{})
require.Equal(t, false, c2.Output())
}
func TestPermalinkPattern(t *testing.T) {
site := siteMock{config.Default()}
c1 := New(site, "c", map[string]interface{}{})
require.Contains(t, c1.PermalinkPattern(), ":collection")
c2 := New(site, "c", map[string]interface{}{"permalink": "out"})
require.Equal(t, "out", c2.PermalinkPattern())
c3 := New(site, "posts", map[string]interface{}{})
require.Contains(t, c3.PermalinkPattern(), "/:year/:month/:day/:title")
}
func TestReadPosts(t *testing.T) {
site := siteMock{config.FromString("source: testdata")}
c := New(site, "posts", map[string]interface{}{})
require.NoError(t, c.ReadPages())
require.Len(t, c.Pages(), 1)
site = siteMock{config.FromString("source: testdata\nunpublished: true")}
c = New(site, "posts", map[string]interface{}{})
require.NoError(t, c.ReadPages())
require.Len(t, c.Pages(), 2)
site = siteMock{config.FromString("source: testdata\nfuture: true")}
c = New(site, "posts", map[string]interface{}{})
require.NoError(t, c.ReadPages())
require.Len(t, c.Pages(), 2)
}