Add some schemaless BaseURL tests

See #2085
This commit is contained in:
Bjørn Erik Pedersen 2016-04-17 19:55:38 +02:00
parent 215b8939bd
commit 77159b4b9b

View file

@ -628,9 +628,10 @@ func TestAbsURLify(t *testing.T) {
{filepath.FromSlash("sect/doc1.html"), []byte("<!doctype html><html><head></head><body><a href=\"#frag1\">link</a></body></html>")},
{filepath.FromSlash("content/blue/doc2.html"), []byte("---\nf: t\n---\n<!doctype html><html><body>more content</body></html>")},
}
for _, baseURL := range []string{"http://auth/bub", "http://base", "//base"} {
for _, canonify := range []bool{true, false} {
viper.Set("CanonifyURLs", canonify)
viper.Set("BaseURL", "http://auth/bub")
viper.Set("BaseURL", baseURL)
s := &Site{
Source: &source.InMemorySource{ByteSource: sources},
targets: targetList{page: &target.PagePub{UglyURLs: true}},
@ -655,7 +656,7 @@ func TestAbsURLify(t *testing.T) {
tests := []struct {
file, expected string
}{
{"content/blue/doc2.html", "<a href=\"http://auth/bub/foobar.jpg\">Going</a>"},
{"content/blue/doc2.html", "<a href=\"%s/foobar.jpg\">Going</a>"},
{"sect/doc1.html", "<!doctype html><html><head></head><body><a href=\"#frag1\">link</a></body></html>"},
}
@ -670,12 +671,17 @@ func TestAbsURLify(t *testing.T) {
expected := test.expected
if strings.Contains(expected, "%s") {
expected = fmt.Sprintf(expected, baseURL)
}
if !canonify {
expected = strings.Replace(expected, viper.GetString("baseurl"), "", -1)
expected = strings.Replace(expected, baseURL, "", -1)
}
if content != expected {
t.Errorf("AbsURLify content expected:\n%q\ngot\n%q", expected, content)
t.Errorf("AbsURLify with baseURL %q content expected:\n%q\ngot\n%q", baseURL, expected, content)
}
}
}
}