1
0
mirror of https://github.com/danog/gojekyll.git synced 2025-01-23 06:01:20 +01:00
gojekyll/collection/collection_test.go

58 lines
1.8 KiB
Go
Raw Permalink Normal View History

2017-07-04 09:09:36 -04:00
package collection
2017-06-22 17:53:46 -04:00
import (
"testing"
2017-07-01 14:55:50 -04:00
"github.com/osteele/gojekyll/config"
2017-07-10 13:23:51 -04:00
"github.com/osteele/gojekyll/pipelines"
2017-06-22 17:53:46 -04:00
"github.com/stretchr/testify/require"
)
2017-07-03 11:48:06 -04:00
type siteMock struct{ c config.Config }
2017-06-22 17:53:46 -04:00
2017-07-10 13:23:51 -04:00
func (c siteMock) Config() *config.Config { return &c.c }
2017-07-10 14:14:42 -04:00
func (c siteMock) Exclude(string) bool { return false }
2017-07-10 13:23:51 -04:00
func (c siteMock) OutputExt(s string) string { return "" }
func (c siteMock) RenderingPipeline() pipelines.PipelineInterface { panic("unimplemented") }
2017-06-23 14:57:28 -04:00
func TestNewCollection(t *testing.T) {
2017-07-03 11:48:06 -04:00
site := siteMock{config.Default()}
2017-06-23 14:57:28 -04:00
2017-07-04 09:09:36 -04:00
c1 := New(site, "c", map[string]interface{}{"output": true})
2017-06-23 14:57:28 -04:00
require.Equal(t, true, c1.Output())
require.Equal(t, "_c/", c1.PathPrefix())
2017-07-04 09:09:36 -04:00
c2 := New(site, "c", map[string]interface{}{})
2017-06-23 14:57:28 -04:00
require.Equal(t, false, c2.Output())
}
func TestPermalinkPattern(t *testing.T) {
2017-07-03 11:48:06 -04:00
site := siteMock{config.Default()}
2017-06-23 14:57:28 -04:00
2017-07-04 09:09:36 -04:00
c1 := New(site, "c", map[string]interface{}{})
2017-06-23 14:57:28 -04:00
require.Contains(t, c1.PermalinkPattern(), ":collection")
2017-07-04 09:09:36 -04:00
c2 := New(site, "c", map[string]interface{}{"permalink": "out"})
2017-06-23 14:57:28 -04:00
require.Equal(t, "out", c2.PermalinkPattern())
2017-07-04 09:09:36 -04:00
c3 := New(site, "posts", map[string]interface{}{})
2017-06-23 14:57:28 -04:00
require.Contains(t, c3.PermalinkPattern(), "/:year/:month/:day/:title")
2017-06-22 17:53:46 -04:00
}
2017-07-03 11:48:06 -04:00
func TestReadPosts(t *testing.T) {
site := siteMock{config.FromString("source: testdata")}
2017-07-04 09:09:36 -04:00
c := New(site, "posts", map[string]interface{}{})
2017-07-03 13:03:45 -04:00
require.NoError(t, c.ReadPages())
2017-07-03 11:48:06 -04:00
require.Len(t, c.Pages(), 1)
site = siteMock{config.FromString("source: testdata\nunpublished: true")}
2017-07-04 09:09:36 -04:00
c = New(site, "posts", map[string]interface{}{})
2017-07-03 13:03:45 -04:00
require.NoError(t, c.ReadPages())
2017-07-03 11:48:06 -04:00
require.Len(t, c.Pages(), 2)
site = siteMock{config.FromString("source: testdata\nfuture: true")}
2017-07-04 09:09:36 -04:00
c = New(site, "posts", map[string]interface{}{})
2017-07-03 13:03:45 -04:00
require.NoError(t, c.ReadPages())
2017-07-03 11:48:06 -04:00
require.Len(t, c.Pages(), 2)
}