summaryrefslogtreecommitdiffstats
path: root/source/file_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-02-05 10:20:06 +0700
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-02-17 17:15:26 +0100
commit93ca7c9e958e34469a337e4efcc7c75774ec50fd (patch)
tree5dfa296cfe74fd5ef8f0d41ea4078704f453aa04 /source/file_test.go
parente34af6ee30f70f5780a281e2fd8f4ed9b487ee61 (diff)
all: Refactor to nonglobal Viper, i18n etc.
This is a final rewrite that removes all the global state in Hugo, which also enables the use if `t.Parallel` in tests. Updates #2701 Fixes #3016
Diffstat (limited to 'source/file_test.go')
-rw-r--r--source/file_test.go26
1 files changed, 19 insertions, 7 deletions
diff --git a/source/file_test.go b/source/file_test.go
index 517474012..d87a154f5 100644
--- a/source/file_test.go
+++ b/source/file_test.go
@@ -18,28 +18,40 @@ import (
"strings"
"testing"
+ "github.com/spf13/hugo/hugofs"
+ "github.com/spf13/viper"
+
"github.com/stretchr/testify/assert"
)
func TestFileUniqueID(t *testing.T) {
+ ss := newTestSourceSpec()
+
f1 := File{uniqueID: "123"}
- f2 := NewFile("a")
+ f2 := ss.NewFile("a")
assert.Equal(t, "123", f1.UniqueID())
assert.Equal(t, "0cc175b9c0f1b6a831c399e269772661", f2.UniqueID())
- f3 := NewFile(filepath.FromSlash("test1/index.md"))
- f4 := NewFile(filepath.FromSlash("test2/index.md"))
+ f3 := ss.NewFile(filepath.FromSlash("test1/index.md"))
+ f4 := ss.NewFile(filepath.FromSlash("test2/index.md"))
assert.NotEqual(t, f3.UniqueID(), f4.UniqueID())
}
func TestFileString(t *testing.T) {
- assert.Equal(t, "abc", NewFileWithContents("a", strings.NewReader("abc")).String())
- assert.Equal(t, "", NewFile("a").String())
+ ss := newTestSourceSpec()
+ assert.Equal(t, "abc", ss.NewFileWithContents("a", strings.NewReader("abc")).String())
+ assert.Equal(t, "", ss.NewFile("a").String())
}
func TestFileBytes(t *testing.T) {
- assert.Equal(t, []byte("abc"), NewFileWithContents("a", strings.NewReader("abc")).Bytes())
- assert.Equal(t, []byte(""), NewFile("a").Bytes())
+ ss := newTestSourceSpec()
+ assert.Equal(t, []byte("abc"), ss.NewFileWithContents("a", strings.NewReader("abc")).Bytes())
+ assert.Equal(t, []byte(""), ss.NewFile("a").Bytes())
+}
+
+func newTestSourceSpec() SourceSpec {
+ v := viper.New()
+ return SourceSpec{Fs: hugofs.NewMem(v), Cfg: v}
}