1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-12-12 14:47:25 +01:00
gojekyll/collection/collection_test.go

56 lines
1.6 KiB
Go
Raw Normal View History

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