12345678910111213141516171819202122232425262728293031323334353637383940414243444546 | package render_test
import (
"bytes"
"os"
"strings"
"testing"
)
// Check reports on the writer it is given. Directories a first render
// would create and sections naming absent repositories are warnings only.
func TestCheckWarnings(t *testing.T) {
e := newEnv(t, "proj", "sections:\n - title: Tools\n repos: [proj, missing]\n")
var out bytes.Buffer
if err := e.site.Check(&out, "repo-render.yaml"); err != nil {
t.Fatalf("Check: %v\n%s", err, out.String())
}
mustContain(t, "report", out.String(), "git: ", "config: repo-render.yaml\n",
"warning: "+e.site.Lay.Htdocs+" does not exist yet",
`warning: section "Tools" lists "missing"`, "\nok\n")
mustNotContain(t, "report", out.String(), `lists "proj"`, "warning: "+e.site.Lay.GitBase+" ")
}
// A lexer that resolves to plain text, and git failing, are problems.
func TestCheckProblems(t *testing.T) {
e := newEnv(t, "proj", "lexers:\n plaintext:\n globs: [\"*.txt\"]\n go:\n globs: [\"*.go\"]\n")
var out bytes.Buffer
err := e.site.Check(&out, "repo-render.yaml")
if err == nil || !strings.Contains(err.Error(), `lexer "plaintext" resolves to plain text`) {
t.Errorf("Check = %v, want the plaintext lexer reported", err)
}
mustContain(t, "report", out.String(), "lexer go: ok")
mustNotContain(t, "report", out.String(), "\nok\n")
// git cannot start in a git_dir that is gone.
e = newEnv(t, "proj", "")
if err := os.RemoveAll(e.site.Lay.GitBase); err != nil {
t.Fatal(err)
}
out.Reset()
err = e.site.Check(&out, "repo-render.yaml")
if err == nil || !strings.Contains(err.Error(), "git cannot run inside "+e.site.Lay.GitBase) {
t.Errorf("Check without git_dir = %v", err)
}
mustNotContain(t, "report", out.String(), "\nok\n")
}
|