diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-01-10 10:55:03 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-02-04 11:37:25 +0700 |
commit | c71e1b106e6011d148cac899f83c4685dee33a22 (patch) | |
tree | c5c7090f0c2398c7771e4908ebcc97aa7714ffd2 /create/content_test.go | |
parent | 0ada40591216572b0e4c6a8ab986b0aa4fb13c13 (diff) |
all: Refactor to nonglobal file systems
Updates #2701
Fixes #2951
Diffstat (limited to 'create/content_test.go')
-rw-r--r-- | create/content_test.go | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/create/content_test.go b/create/content_test.go index cdee13fb8..df29527fe 100644 --- a/create/content_test.go +++ b/create/content_test.go @@ -19,23 +19,22 @@ import ( "strings" "testing" + "github.com/spf13/hugo/hugolib" + "fmt" + "github.com/spf13/hugo/hugofs" + "github.com/spf13/afero" "github.com/spf13/hugo/create" "github.com/spf13/hugo/helpers" - "github.com/spf13/hugo/hugofs" "github.com/spf13/viper" + "github.com/stretchr/testify/require" ) func TestNewContent(t *testing.T) { initViper() - err := initFs() - if err != nil { - t.Fatalf("initialization error: %s", err) - } - cases := []struct { kind string path string @@ -48,15 +47,15 @@ func TestNewContent(t *testing.T) { {"product", "product/sample-4.md", []string{`title = "sample 4"`}}, // empty archetype front matter } - for i, c := range cases { - err = create.NewContent(hugofs.Source(), c.kind, c.path) - if err != nil { - t.Errorf("[%d] NewContent: %s", i, err) - } + for _, c := range cases { + s, err := hugolib.NewEnglishSite() + require.NoError(t, err) + require.NoError(t, initFs(s.Fs)) - fname := filepath.Join("content", filepath.FromSlash(c.path)) - content := readFileFromFs(t, hugofs.Source(), fname) + require.NoError(t, create.NewContent(s, c.kind, c.path)) + fname := filepath.Join("content", filepath.FromSlash(c.path)) + content := readFileFromFs(t, s.Fs.Source, fname) for i, v := range c.expected { found := strings.Contains(content, v) if !found { @@ -72,11 +71,11 @@ func initViper() { viper.Set("archetypeDir", "archetypes") viper.Set("contentDir", "content") viper.Set("themesDir", "themes") + viper.Set("layoutDir", "layouts") viper.Set("theme", "sample") } -func initFs() error { - hugofs.InitMemFs() +func initFs(fs *hugofs.Fs) error { perm := os.FileMode(0755) var err error @@ -87,7 +86,7 @@ func initFs() error { filepath.Join("themes", "sample", "archetypes"), } for _, dir := range dirs { - err = hugofs.Source().Mkdir(dir, perm) + err = fs.Source.Mkdir(dir, perm) if err != nil { return err } @@ -111,7 +110,7 @@ func initFs() error { content: "+++\ndate =\"\"\ntitle = \"Empty Date Arch title\"\ntest = \"test1\"\n+++\n", }, } { - f, err := hugofs.Source().Create(v.path) + f, err := fs.Source.Create(v.path) if err != nil { return err } |