tests: Convert from testify to quicktest

This commit is contained in:
Bjørn Erik Pedersen
2019-08-10 21:05:17 +02:00
parent 6027ee1108
commit 9e57182705
195 changed files with 3919 additions and 3693 deletions

View File

@@ -19,12 +19,12 @@ import (
"github.com/gohugoio/hugo/helpers"
qt "github.com/frankban/quicktest"
"github.com/gohugoio/hugo/hugofs"
"github.com/stretchr/testify/require"
)
func TestIgnoreDotFilesAndDirectories(t *testing.T) {
assert := require.New(t)
c := qt.New(t)
tests := []struct {
path string
@@ -55,7 +55,7 @@ func TestIgnoreDotFilesAndDirectories(t *testing.T) {
v.Set("ignoreFiles", test.ignoreFilesRegexpes)
fs := hugofs.NewMem(v)
ps, err := helpers.NewPathSpec(fs, v, nil)
assert.NoError(err)
c.Assert(err, qt.IsNil)
s := NewSourceSpec(ps, fs.Source)

View File

@@ -18,11 +18,11 @@ import (
"strings"
"testing"
"github.com/stretchr/testify/require"
qt "github.com/frankban/quicktest"
)
func TestFileInfo(t *testing.T) {
assert := require.New(t)
c := qt.New(t)
s := newTestSourceSpec()
@@ -32,29 +32,29 @@ func TestFileInfo(t *testing.T) {
assert func(f *FileInfo)
}{
{filepath.FromSlash("/a/"), filepath.FromSlash("/a/b/page.md"), func(f *FileInfo) {
assert.Equal(filepath.FromSlash("/a/b/page.md"), f.Filename())
assert.Equal(filepath.FromSlash("b/"), f.Dir())
assert.Equal(filepath.FromSlash("b/page.md"), f.Path())
assert.Equal("b", f.Section())
assert.Equal(filepath.FromSlash("page"), f.TranslationBaseName())
assert.Equal(filepath.FromSlash("page"), f.BaseFileName())
c.Assert(f.Filename(), qt.Equals, filepath.FromSlash("/a/b/page.md"))
c.Assert(f.Dir(), qt.Equals, filepath.FromSlash("b/"))
c.Assert(f.Path(), qt.Equals, filepath.FromSlash("b/page.md"))
c.Assert(f.Section(), qt.Equals, "b")
c.Assert(f.TranslationBaseName(), qt.Equals, filepath.FromSlash("page"))
c.Assert(f.BaseFileName(), qt.Equals, filepath.FromSlash("page"))
}},
{filepath.FromSlash("/a/"), filepath.FromSlash("/a/b/c/d/page.md"), func(f *FileInfo) {
assert.Equal("b", f.Section())
c.Assert(f.Section(), qt.Equals, "b")
}},
{filepath.FromSlash("/a/"), filepath.FromSlash("/a/b/page.en.MD"), func(f *FileInfo) {
assert.Equal("b", f.Section())
assert.Equal(filepath.FromSlash("b/page.en.MD"), f.Path())
assert.Equal(filepath.FromSlash("page"), f.TranslationBaseName())
assert.Equal(filepath.FromSlash("page.en"), f.BaseFileName())
c.Assert(f.Section(), qt.Equals, "b")
c.Assert(f.Path(), qt.Equals, filepath.FromSlash("b/page.en.MD"))
c.Assert(f.TranslationBaseName(), qt.Equals, filepath.FromSlash("page"))
c.Assert(f.BaseFileName(), qt.Equals, filepath.FromSlash("page.en"))
}},
} {
path := strings.TrimPrefix(this.filename, this.base)
f, err := s.NewFileInfoFrom(path, this.filename)
assert.NoError(err)
c.Assert(err, qt.IsNil)
this.assert(f)
}

View File

@@ -25,19 +25,19 @@ import (
"github.com/spf13/afero"
qt "github.com/frankban/quicktest"
"github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/hugofs"
"github.com/stretchr/testify/require"
"github.com/spf13/viper"
)
func TestEmptySourceFilesystem(t *testing.T) {
assert := require.New(t)
c := qt.New(t)
ss := newTestSourceSpec()
src := ss.NewFilesystem("")
files, err := src.Files()
assert.NoError(err)
c.Assert(err, qt.IsNil)
if len(files) != 0 {
t.Errorf("new filesystem should contain 0 files.")
}
@@ -49,7 +49,7 @@ func TestUnicodeNorm(t *testing.T) {
return
}
assert := require.New(t)
c := qt.New(t)
paths := []struct {
NFC string
@@ -64,11 +64,11 @@ func TestUnicodeNorm(t *testing.T) {
for i, path := range paths {
base := fmt.Sprintf("base%d", i)
assert.NoError(afero.WriteFile(ss.Fs.Source, filepath.Join(base, path.NFD), []byte("some data"), 0777))
c.Assert(afero.WriteFile(ss.Fs.Source, filepath.Join(base, path.NFD), []byte("some data"), 0777), qt.IsNil)
src := ss.NewFilesystem(base)
_ = src.add(path.NFD, fi)
files, err := src.Files()
assert.NoError(err)
c.Assert(err, qt.IsNil)
f := files[0]
if f.BaseFileName() != path.NFC {
t.Fatalf("file %q name in NFD form should be normalized (%s)", f.BaseFileName(), path.NFC)