mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
Introduce unit testing for page.go
This commit is contained in:
parent
fa55cd9857
commit
274d324c8b
3 changed files with 24 additions and 9 deletions
|
@ -78,10 +78,9 @@ func (p Pages) Limit(n int) Pages { return p[0:n] }
|
|||
|
||||
func initializePage(filename string) (page Page) {
|
||||
page = Page{contentType: "",
|
||||
File: File{FileName: filename,
|
||||
Extension: "html"},
|
||||
File: File{FileName: filename, Extension: "html"},
|
||||
Node: Node{Keywords: make([]string, 10, 30)},
|
||||
Params: make(map[string]interface{}),
|
||||
Node: Node{Keywords: make([]string, 10, 30)},
|
||||
Markup: "md"}
|
||||
page.Date, _ = time.Parse("20060102", "20080101")
|
||||
page.setSection()
|
||||
|
|
|
@ -1,17 +1,33 @@
|
|||
package hugolib
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDegenerateMissingFolderInPageFilename(t *testing.T) {
|
||||
p := NewPage(filepath.Join("foobar"))
|
||||
if p != nil {
|
||||
t.Fatalf("Creating a new Page without a subdirectory should result in nil page")
|
||||
if p.Section != "" {
|
||||
t.Fatalf("No section should be set for a file path: foobar")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateNewPage(t *testing.T) {
|
||||
toCheck := []map[string]string{
|
||||
{"input": filepath.Join("sub", "foobar.html"), "expect": "sub"},
|
||||
{"input": filepath.Join("content", "sub", "foobar.html"), "expect": "sub"},
|
||||
{"input": filepath.Join("content", "dub", "sub", "foobar.html"), "expect": "sub"},
|
||||
}
|
||||
|
||||
for _, el := range toCheck {
|
||||
p := NewPage(el["input"])
|
||||
if p.Section != el["expect"] {
|
||||
t.Fatalf("Section not set to %s for page %s. Got: %s", el["expect"], el["input"], p.Section)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func TestSettingOutFileOnPageContainsCorrectSlashes(t *testing.T) {
|
||||
s := NewSite(&Config{})
|
||||
p := NewPage(filepath.Join("sub", "foobar"))
|
||||
|
|
|
@ -297,7 +297,7 @@ func (s *Site) RenderPages() error {
|
|||
|
||||
func (s *Site) WritePages() {
|
||||
for _, p := range s.Pages {
|
||||
s.WritePublic(p.Section + slash + p.OutFile, p.RenderedContent.Bytes())
|
||||
s.WritePublic(p.Section+slash+p.OutFile, p.RenderedContent.Bytes())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -409,7 +409,7 @@ func (s *Site) RenderLists() error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.WritePublic(section + slash + "index.html", x.Bytes())
|
||||
s.WritePublic(section+slash+"index.html", x.Bytes())
|
||||
|
||||
if a := s.Tmpl.Lookup("rss.xml"); a != nil {
|
||||
// XML Feed
|
||||
|
@ -417,7 +417,7 @@ func (s *Site) RenderLists() error {
|
|||
n.Permalink = template.HTML(string(n.Site.BaseUrl) + n.Url)
|
||||
y := s.NewXMLBuffer()
|
||||
s.Tmpl.ExecuteTemplate(y, "rss.xml", n)
|
||||
s.WritePublic(section + slash + "index.xml", y.Bytes())
|
||||
s.WritePublic(section+slash+"index.xml", y.Bytes())
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
|
Loading…
Reference in a new issue