2017-07-05 18:44:38 +02:00
|
|
|
package site
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2022-01-29 20:17:23 +01:00
|
|
|
"github.com/danog/gojekyll/config"
|
|
|
|
"github.com/danog/gojekyll/pages"
|
|
|
|
"github.com/danog/liquid/tags"
|
2017-07-05 18:44:38 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func readTestSiteDrop(t *testing.T) map[string]interface{} {
|
|
|
|
site, err := FromDirectory("testdata/site1", config.Flags{})
|
|
|
|
require.NoError(t, err)
|
2017-07-09 01:57:41 +02:00
|
|
|
require.NoError(t, site.Read())
|
2017-08-21 21:06:53 +02:00
|
|
|
return site.ToLiquid().(tags.IterationKeyedMap)
|
2017-07-05 18:44:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO test cases for collections, categories, tags, data
|
|
|
|
|
2017-07-07 01:31:36 +02:00
|
|
|
func TestSite_ToLiquid(t *testing.T) {
|
2017-07-05 18:44:38 +02:00
|
|
|
drop := readTestSiteDrop(t)
|
2017-09-03 18:18:17 +02:00
|
|
|
docs, ok := drop["documents"].([]Page)
|
2017-07-28 00:07:42 +02:00
|
|
|
require.True(t, ok, fmt.Sprintf("documents has type %T", drop["documents"]))
|
2017-08-20 20:53:05 +02:00
|
|
|
require.Len(t, docs, 3)
|
2017-07-05 18:44:38 +02:00
|
|
|
}
|
2017-07-28 00:07:42 +02:00
|
|
|
|
2017-07-05 18:44:38 +02:00
|
|
|
func TestSite_ToLiquid_time(t *testing.T) {
|
|
|
|
drop := readTestSiteDrop(t)
|
|
|
|
_, ok := drop["time"].(time.Time)
|
|
|
|
require.True(t, ok)
|
|
|
|
// TODO read time from config if present
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSite_ToLiquid_pages(t *testing.T) {
|
|
|
|
drop := readTestSiteDrop(t)
|
2017-09-03 18:18:17 +02:00
|
|
|
ps, ok := drop["pages"]
|
2017-07-05 18:44:38 +02:00
|
|
|
require.True(t, ok, fmt.Sprintf("pages has type %T", drop["pages"]))
|
2021-06-18 14:01:10 +02:00
|
|
|
require.Len(t, ps, 2)
|
2017-07-07 18:24:00 +02:00
|
|
|
|
2017-09-03 18:18:17 +02:00
|
|
|
ps, ok = drop["html_pages"]
|
2017-07-07 18:24:00 +02:00
|
|
|
require.True(t, ok, fmt.Sprintf("pages has type %T", drop["pages"]))
|
2021-06-18 14:01:10 +02:00
|
|
|
require.Len(t, ps, 2)
|
2017-07-05 18:44:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSite_ToLiquid_posts(t *testing.T) {
|
|
|
|
drop := readTestSiteDrop(t)
|
2017-09-03 18:18:17 +02:00
|
|
|
posts, ok := drop["posts"].([]Page)
|
2017-07-05 18:44:38 +02:00
|
|
|
require.True(t, ok, fmt.Sprintf("posts has type %T", drop["posts"]))
|
|
|
|
require.Len(t, posts, 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSite_ToLiquid_related_posts(t *testing.T) {
|
|
|
|
drop := readTestSiteDrop(t)
|
2017-09-03 18:18:17 +02:00
|
|
|
posts, ok := drop["related_posts"].([]Page)
|
2017-07-05 18:44:38 +02:00
|
|
|
require.True(t, ok, fmt.Sprintf("related_posts has type %T", drop["related_posts"]))
|
|
|
|
require.Len(t, posts, 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSite_ToLiquid_static_files(t *testing.T) {
|
|
|
|
drop := readTestSiteDrop(t)
|
|
|
|
files, ok := drop["static_files"].([]*pages.StaticFile)
|
|
|
|
require.True(t, ok, fmt.Sprintf("static_files has type %T", drop["static_files"]))
|
|
|
|
require.Len(t, files, 1)
|
|
|
|
|
2017-08-16 00:55:18 +02:00
|
|
|
f := files[0].ToLiquid().(tags.IterationKeyedMap)
|
2017-07-20 17:32:52 +02:00
|
|
|
require.IsType(t, "", f["path"])
|
|
|
|
require.IsType(t, time.Now(), f["modified_time"])
|
2017-07-05 18:44:38 +02:00
|
|
|
require.Equal(t, ".html", f["extname"])
|
|
|
|
}
|