2013-11-10 20:04:51 +00:00
|
|
|
package hugolib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2013-11-24 21:48:57 +00:00
|
|
|
"testing"
|
2014-04-07 15:44:13 +00:00
|
|
|
|
|
|
|
"github.com/spf13/viper"
|
2013-11-10 20:04:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const SITE_INFO_PARAM_TEMPLATE = `{{ .Site.Params.MyGlobalParam }}`
|
|
|
|
|
|
|
|
func TestSiteInfoParams(t *testing.T) {
|
2014-04-07 15:44:13 +00:00
|
|
|
viper.Set("Params", map[string]interface{}{"MyGlobalParam": "FOOBAR_PARAM"})
|
|
|
|
s := &Site{}
|
2013-11-10 20:04:51 +00:00
|
|
|
|
|
|
|
s.initialize()
|
|
|
|
if s.Info.Params["MyGlobalParam"] != "FOOBAR_PARAM" {
|
|
|
|
t.Errorf("Unable to set site.Info.Param")
|
|
|
|
}
|
|
|
|
s.prepTemplates()
|
|
|
|
s.addTemplate("template", SITE_INFO_PARAM_TEMPLATE)
|
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
|
|
|
|
err := s.renderThing(s.NewNode(), "template", buf)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Unable to render template: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if buf.String() != "FOOBAR_PARAM" {
|
|
|
|
t.Errorf("Expected FOOBAR_PARAM: got %s", buf.String())
|
|
|
|
}
|
|
|
|
}
|
2014-05-11 00:27:49 +00:00
|
|
|
|
2015-03-05 22:19:10 +00:00
|
|
|
func TestSiteInfoPermalinks(t *testing.T) {
|
2014-05-11 00:27:49 +00:00
|
|
|
viper.Set("Permalinks", map[string]interface{}{"section": "/:title"})
|
|
|
|
s := &Site{}
|
|
|
|
|
|
|
|
s.initialize()
|
|
|
|
permalink := s.Info.Permalinks["section"]
|
|
|
|
|
|
|
|
if permalink != "/:title" {
|
|
|
|
t.Errorf("Could not set permalink (%#v)", permalink)
|
|
|
|
}
|
|
|
|
}
|