summaryrefslogtreecommitdiffstats
path: root/hugolib/rss_test.go
diff options
context:
space:
mode:
authorNoah Campbell <noahcampbell@gmail.com>2013-11-05 05:29:37 +0000
committerNoah Campbell <noahcampbell@gmail.com>2013-11-05 07:03:02 +0000
commit1cebce12ad2335e1140646763dd56009c57d6495 (patch)
tree9026883f1545f1246c52a7b089ed1ffa64d88a4e /hugolib/rss_test.go
parentb22364570be6c6add79af21a90de8c5f7a775813 (diff)
Adding RSS test case.
Checks to make sure the xml document starts with <?xml. Previously, the html translate package would write additional details into the document that caused it to fail.
Diffstat (limited to 'hugolib/rss_test.go')
-rw-r--r--hugolib/rss_test.go65
1 files changed, 65 insertions, 0 deletions
diff --git a/hugolib/rss_test.go b/hugolib/rss_test.go
new file mode 100644
index 000000000..b4c9e01d7
--- /dev/null
+++ b/hugolib/rss_test.go
@@ -0,0 +1,65 @@
+package hugolib
+
+import (
+ "testing"
+ "bytes"
+ "github.com/spf13/hugo/source"
+ "github.com/spf13/hugo/target"
+)
+
+const RSS_TEMPLATE = `<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
+ <channel>
+ <title>{{ .Title }} on {{ .Site.Title }} </title>
+ <link>{{ .Permalink }}</link>
+ <language>en-us</language>
+ <author>Steve Francia</author>
+ <rights>Francia; all rights reserved.</rights>
+ <updated>{{ .Date }}</updated>
+ {{ range .Data.Pages }}
+ <item>
+ <title>{{ .Title }}</title>
+ <link>{{ .Permalink }}</link>
+ <pubDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 MST" }}</pubDate>
+ <author>Steve Francia</author>
+ <guid>{{ .Permalink }}</guid>
+ <description>{{ .Content | html }}</description>
+ </item>
+ {{ end }}
+ </channel>
+</rss>`
+
+func TestRSSOutput(t *testing.T) {
+ files := make(map[string][]byte)
+ target := &target.InMemoryTarget{Files: files}
+ s := &Site{
+ Target: target,
+ Config: Config{BaseUrl: "http://auth/bub/"},
+ Source: &source.InMemorySource{WEIGHTED_SOURCES},
+ }
+ s.initializeSiteInfo()
+ s.prepTemplates()
+ // Add an rss.xml template to invoke the rss build.
+ s.addTemplate("rss.xml", RSS_TEMPLATE)
+
+ if err := s.CreatePages(); err != nil {
+ t.Fatalf("Unable to create pages: %s", err)
+ }
+
+ if err := s.BuildSiteMeta(); err != nil {
+ t.Fatalf("Unable to build site metadata: %s", err)
+ }
+
+ if err := s.RenderHomePage(); err != nil {
+ t.Fatalf("Unable to RenderHomePage: %s", err)
+ }
+
+ if _, ok := files[".xml"]; !ok {
+ t.Errorf("Unable to locate: %s", ".xml")
+ t.Logf("%q", files)
+ }
+
+ rss, _ := files[".xml"]
+ if !bytes.HasPrefix(rss, []byte("<?xml")) {
+ t.Errorf("rss feed should start with <?xml. %s", rss)
+ }
+}