1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
package hugolib
import (
"bytes"
"io"
"testing"
)
const SLUG_DOC_1 = "---\ntitle: slug doc 1\nslug: slug-doc-1\naliases:\n - sd1/foo/\n - sd2\n - sd3/\n - sd4.php\n---\nslug doc 1 content"
//const SLUG_DOC_1 = "---\ntitle: slug doc 1\nslug: slug-doc-1\n---\nslug doc 1 content"
const SLUG_DOC_2 = "---\ntitle: slug doc 2\nslug: slug-doc-2\n---\nslug doc 2 content"
const INDEX_TEMPLATE = "{{ range .Data.Pages }}.{{ end }}"
func must(err error) {
if err != nil {
panic(err)
}
}
func mustReturn(ret *Page, err error) *Page {
if err != nil {
panic(err)
}
return ret
}
type InMemoryTarget struct {
files map[string][]byte
}
func (t *InMemoryTarget) Publish(label string, reader io.Reader) (err error) {
if t.files == nil {
t.files = make(map[string][]byte)
}
bytes := new(bytes.Buffer)
bytes.ReadFrom(reader)
t.files[label] = bytes.Bytes()
return
}
func (t *InMemoryTarget) Translate(label string) (dest string, err error) {
return label, nil
}
var urlFakeSource = []byteSource{
{"content/blue/doc1.md", []byte(SLUG_DOC_1)},
{"content/blue/doc2.md", []byte(SLUG_DOC_2)},
}
func TestPageCount(t *testing.T) {
target := new(InMemoryTarget)
s := &Site{
Target: target,
Config: Config{UglyUrls: false},
Source: &inMemorySource{urlFakeSource},
}
s.initializeSiteInfo()
s.prepTemplates()
must(s.addTemplate("indexes/blue.html", INDEX_TEMPLATE))
if err := s.CreatePages(); err != nil {
t.Errorf("Unable to create pages: %s", err)
}
if err := s.BuildSiteMeta(); err != nil {
t.Errorf("Unable to build site metadata: %s", err)
}
if err := s.RenderLists(); err != nil {
t.Errorf("Unable to render site lists: %s", err)
}
if err := s.RenderAliases(); err != nil {
t.Errorf("Unable to render site lists: %s", err)
}
blueIndex := target.files["blue"]
if blueIndex == nil {
t.Errorf("No indexed rendered. %v", target.files)
}
if len(blueIndex) != 2 {
t.Errorf("Number of pages does not equal 2, got %d. %q", len(blueIndex), blueIndex)
}
for _, s := range []string{
"sd1/foo/index.html",
"sd2",
"sd3/index.html",
"sd4.php",
} {
if _, ok := target.files[s]; !ok {
t.Errorf("No alias rendered: %s", s)
}
}
}
|