mirror of
https://github.com/danog/gojekyll.git
synced 2024-12-12 17:47:19 +01:00
56 lines
1.6 KiB
Go
56 lines
1.6 KiB
Go
package collection
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/osteele/gojekyll/config"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
type siteMock struct{ c config.Config }
|
|
|
|
func (c siteMock) Config() *config.Config { return &c.c }
|
|
func (c siteMock) OutputExt(s string) string { return "" }
|
|
func (c siteMock) Site() interface{} { return c }
|
|
|
|
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)
|
|
}
|