|
|
|
package caddyhugo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
type World struct {
|
|
|
|
CH CaddyHugo
|
|
|
|
BlogFolder string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w World) Clean() {
|
|
|
|
if w.BlogFolder != "" {
|
|
|
|
os.RemoveAll(w.BlogFolder)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewWorld(t *testing.T) World {
|
|
|
|
dir, err := ioutil.TempDir("", "caddy-hugo2-test-")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error initializing test environment: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
w := World{BlogFolder: dir}
|
|
|
|
|
|
|
|
cmd := exec.Command("hugo", "new", "site", dir)
|
|
|
|
cmd.Dir = dir
|
|
|
|
out, err := cmd.CombinedOutput()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error initializing test site: %v\n\n%v", err, string(out))
|
|
|
|
}
|
|
|
|
|
|
|
|
w.CH.Setup(dir)
|
|
|
|
|
|
|
|
return w
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDoc(t *testing.T) {
|
|
|
|
w := NewWorld(t)
|
|
|
|
defer w.Clean()
|
|
|
|
|
|
|
|
c, err := GetContent(w.BlogFolder, w.CH.HugoSites)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("couldn't get content from a blank test environment: %v", err)
|
|
|
|
}
|
|
|
|
if len(c) != 0 {
|
|
|
|
t.Fatalf("expected a blank test environment, but saw %d pages", len(c))
|
|
|
|
}
|
|
|
|
|
|
|
|
w.CH.NewContent("test1", "")
|
|
|
|
c, err = GetContent(w.BlogFolder, w.CH.HugoSites)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("couldn't get content from the test environment: %v", err)
|
|
|
|
}
|
|
|
|
if len(c) != 1 {
|
|
|
|
t.Fatalf("expected 1 page, but saw %d pages", len(c))
|
|
|
|
}
|
|
|
|
|
|
|
|
w.CH.NewContent("TEST 2!!", "")
|
|
|
|
c, err = GetContent(w.BlogFolder, w.CH.HugoSites)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("couldn't get content from the test environment: %v", err)
|
|
|
|
}
|
|
|
|
if len(c) != 2 {
|
|
|
|
t.Fatalf("expected 2 pages, but saw %d pages", len(c))
|
|
|
|
}
|
|
|
|
}
|