1
0
mirror of https://github.com/schollz/cowyo.git synced 2023-08-10 21:13:00 +03:00
cowyo/server/page_test.go

75 lines
1.7 KiB
Go
Raw Permalink Normal View History

package server
2018-02-16 02:50:48 +03:00
import (
"os"
"strings"
"testing"
)
func TestListFiles(t *testing.T) {
pathToData = "testdata"
os.MkdirAll(pathToData, 0755)
defer os.RemoveAll(pathToData)
2018-04-28 05:30:13 +03:00
s := Site{PathToData: pathToData}
p := s.Open("testpage")
2018-02-16 02:50:48 +03:00
p.Update("Some data")
2018-04-28 05:30:13 +03:00
p = s.Open("testpage2")
2018-02-16 02:50:48 +03:00
p.Update("A different bunch of data")
2018-04-28 05:30:13 +03:00
p = s.Open("testpage3")
2018-02-16 02:50:48 +03:00
p.Update("Not much else")
2018-04-28 05:30:13 +03:00
n := s.DirectoryList()
2018-02-16 02:50:48 +03:00
if len(n) != 3 {
t.Error("Expected three directory entries")
t.FailNow()
}
2018-04-28 04:58:26 +03:00
if n[0].Name() != "testpage" {
2018-02-16 02:50:48 +03:00
t.Error("Expected testpage to be first")
}
2018-04-28 04:58:26 +03:00
if n[1].Name() != "testpage2" {
2018-02-16 02:50:48 +03:00
t.Error("Expected testpage2 to be second")
}
2018-04-28 04:58:26 +03:00
if n[2].Name() != "testpage3" {
2018-02-16 02:50:48 +03:00
t.Error("Expected testpage3 to be last")
}
}
func TestGeneral(t *testing.T) {
pathToData = "testdata"
os.MkdirAll(pathToData, 0755)
defer os.RemoveAll(pathToData)
2018-04-28 05:30:13 +03:00
s := Site{PathToData: pathToData}
p := s.Open("testpage")
2018-02-16 02:50:48 +03:00
err := p.Update("**bold**")
if err != nil {
t.Error(err)
}
if strings.TrimSpace(p.RenderedPage) != "<p><strong>bold</strong></p>" {
t.Errorf("Did not render: '%s'", p.RenderedPage)
}
err = p.Update("**bold** and *italic*")
if err != nil {
t.Error(err)
}
p.Save()
2018-04-28 05:30:13 +03:00
p2 := s.Open("testpage")
2018-02-16 02:50:48 +03:00
if strings.TrimSpace(p2.RenderedPage) != "<p><strong>bold</strong> and <em>italic</em></p>" {
t.Errorf("Did not render: '%s'", p2.RenderedPage)
}
2018-04-28 05:30:13 +03:00
p3 := s.Open("testpage: childpage")
2018-02-16 02:50:48 +03:00
err = p3.Update("**child content**")
if err != nil {
t.Error(err)
}
children := p.ChildPageNames()
if len(children) != 1 {
t.Errorf("Expected 1 child page to be found, got %d", len(children))
return
}
if children[0] != "testpage: childpage" {
t.Errorf("Expected child page %s to be found (got %s)", "testpage: childpage", children[0])
}
}