hugo/hugolib/site_show_plan_test.go

59 lines
1.5 KiB
Go
Raw Normal View History

2013-09-01 00:13:04 -04:00
package hugolib
import (
2013-09-01 10:43:29 -04:00
"bytes"
"testing"
2013-09-03 23:52:50 -04:00
"github.com/spf13/hugo/target"
2013-09-01 00:13:04 -04:00
)
2013-09-01 10:43:29 -04:00
func checkShowPlanExpected(t *testing.T, expected, got string) {
if got != expected {
t.Errorf("ShowPlan expected:\n%q\ngot\n%q", expected, got)
}
}
func TestDegenerateNoFiles(t *testing.T) {
s := new(Site)
out := new(bytes.Buffer)
if err := s.ShowPlan(out); err != nil {
t.Errorf("ShowPlan unexpectedly returned an error: %s", err)
2013-09-01 10:43:29 -04:00
}
expected := "No source files provided.\n"
got := out.String()
checkShowPlanExpected(t, expected, got)
}
2013-09-01 00:13:04 -04:00
func TestDegenerateNoTarget(t *testing.T) {
s := new(Site)
2013-09-01 10:43:29 -04:00
s.Files = append(s.Files, "foo/bar/file.md")
2013-09-01 00:13:04 -04:00
out := new(bytes.Buffer)
if err := s.ShowPlan(out); err != nil {
t.Errorf("ShowPlan unexpectedly returned an error: %s", err)
}
2013-09-01 10:43:29 -04:00
2013-09-03 23:52:50 -04:00
expected := "foo/bar/file.md\n canonical => !no target specified!\n"
2013-09-01 10:43:29 -04:00
checkShowPlanExpected(t, expected, out.String())
2013-09-01 00:13:04 -04:00
}
2013-09-03 23:52:50 -04:00
func TestFileTarget(t *testing.T) {
s := &Site{Target: new(target.Filesystem)}
s.Files = append(s.Files, "foo/bar/file.md")
out := new(bytes.Buffer)
s.ShowPlan(out)
expected := "foo/bar/file.md\n canonical => foo/bar/file/index.html\n"
checkShowPlanExpected(t, expected, out.String())
}
func TestFileTargetUgly(t *testing.T) {
s := &Site{Target: &target.Filesystem{UglyUrls: true}}
s.Files = append(s.Files, "foo/bar/file.md")
out := new(bytes.Buffer)
s.ShowPlan(out)
expected := "foo/bar/file.md\n canonical => foo/bar/file.html\n"
checkShowPlanExpected(t, expected, out.String())
}