You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.2 KiB
62 lines
1.2 KiB
7 years ago
|
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))
|
||
|
}
|
||
|
}
|