Updating tests to use new Targets & Writers and switch to using Afero.MemMapFs for more accurate tests.

This commit is contained in:
spf13
2014-11-04 00:41:47 -05:00
parent 7b960ac121
commit 4dcf734acd
6 changed files with 81 additions and 75 deletions

View File

@@ -4,8 +4,10 @@ import (
"bytes"
"testing"
"github.com/spf13/afero"
"github.com/spf13/hugo/helpers"
"github.com/spf13/hugo/hugofs"
"github.com/spf13/hugo/source"
"github.com/spf13/hugo/target"
"github.com/spf13/viper"
)
@@ -31,11 +33,10 @@ const RSS_TEMPLATE = `<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom
</rss>`
func TestRSSOutput(t *testing.T) {
files := make(map[string][]byte)
target := &target.InMemoryTarget{Files: files}
viper.Set("baseurl", "http://auth/bub/")
hugofs.DestinationFS = new(afero.MemMapFs)
s := &Site{
Target: target,
Source: &source.InMemorySource{ByteSource: WEIGHTED_SOURCES},
}
s.initializeSiteInfo()
@@ -55,12 +56,13 @@ func TestRSSOutput(t *testing.T) {
t.Fatalf("Unable to RenderHomePage: %s", err)
}
if _, ok := files[".xml"]; !ok {
t.Errorf("Unable to locate: %s", ".xml")
t.Logf("%q", files)
file, err := hugofs.DestinationFS.Open("rss.xml")
if err != nil {
t.Fatalf("Unable to locate: %s", "rss.xml")
}
rss, _ := files[".xml"]
rss := helpers.ReaderToBytes(file)
if !bytes.HasPrefix(rss, []byte("<?xml")) {
t.Errorf("rss feed should start with <?xml. %s", rss)
}