mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-28 06:30:33 +03:00
Test case for permalink functionality
This commit is contained in:
parent
895638433e
commit
6e1268f45b
1 changed files with 38 additions and 0 deletions
|
@ -1,9 +1,47 @@
|
||||||
package hugolib
|
package hugolib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"html/template"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPermalink(t *testing.T) {
|
func TestPermalink(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
base template.URL
|
||||||
|
expectedAbs string
|
||||||
|
expectedRel string
|
||||||
|
}{
|
||||||
|
{"", "/x/y/z/boofar", "/x/y/z/boofar"},
|
||||||
|
{"http://barnew/", "http://barnew/x/y/z/boofar", "/x/y/z/boofar"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
p := &Page{
|
||||||
|
Node: Node{
|
||||||
|
UrlPath: UrlPath{Section: "x/y/z"},
|
||||||
|
Site: SiteInfo{BaseUrl: test.base},
|
||||||
|
},
|
||||||
|
File: File{FileName: "x/y/z/boofar.md"},
|
||||||
|
}
|
||||||
|
|
||||||
|
u, err := p.Permalink()
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unable to process permalink: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
expected := test.expectedAbs
|
||||||
|
if u != expected {
|
||||||
|
t.Errorf("Expected abs url: %s, got: %s", expected, u)
|
||||||
|
}
|
||||||
|
|
||||||
|
u, err = p.RelPermalink()
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unable to process permalink: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
expected = test.expectedRel
|
||||||
|
if u != expected {
|
||||||
|
t.Errorf("Expected abs url: %s, got: %s", expected, u)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue