diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-08-10 21:05:17 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-08-12 13:26:32 +0200 |
commit | 9e571827055dedb46b78c5db3d17d6913f14870b (patch) | |
tree | f5f0108afe0c9385ff6dc27664943d9f719f57ad /hugofs | |
parent | 6027ee11082d0b9d72de1d4d1980a702be294ad2 (diff) |
tests: Convert from testify to quicktest
Diffstat (limited to 'hugofs')
-rw-r--r-- | hugofs/files/classifier_test.go | 38 | ||||
-rw-r--r-- | hugofs/filter_fs_test.go | 6 | ||||
-rw-r--r-- | hugofs/fs_test.go | 35 | ||||
-rw-r--r-- | hugofs/hashing_fs_test.go | 20 | ||||
-rw-r--r-- | hugofs/nosymlink_test.go | 46 | ||||
-rw-r--r-- | hugofs/rootmapping_fs_test.go | 180 | ||||
-rw-r--r-- | hugofs/walk_test.go | 52 |
7 files changed, 189 insertions, 188 deletions
diff --git a/hugofs/files/classifier_test.go b/hugofs/files/classifier_test.go index d576b4e58..af188f349 100644 --- a/hugofs/files/classifier_test.go +++ b/hugofs/files/classifier_test.go @@ -17,33 +17,33 @@ import ( "path/filepath" "testing" - "github.com/stretchr/testify/require" + qt "github.com/frankban/quicktest" ) func TestIsContentFile(t *testing.T) { - assert := require.New(t) + c := qt.New(t) - assert.True(IsContentFile(filepath.FromSlash("my/file.md"))) - assert.True(IsContentFile(filepath.FromSlash("my/file.ad"))) - assert.False(IsContentFile(filepath.FromSlash("textfile.txt"))) - assert.True(IsContentExt("md")) - assert.False(IsContentExt("json")) + c.Assert(IsContentFile(filepath.FromSlash("my/file.md")), qt.Equals, true) + c.Assert(IsContentFile(filepath.FromSlash("my/file.ad")), qt.Equals, true) + c.Assert(IsContentFile(filepath.FromSlash("textfile.txt")), qt.Equals, false) + c.Assert(IsContentExt("md"), qt.Equals, true) + c.Assert(IsContentExt("json"), qt.Equals, false) } func TestComponentFolders(t *testing.T) { - assert := require.New(t) + c := qt.New(t) // It's important that these are absolutely right and not changed. - assert.Equal(len(ComponentFolders), len(componentFoldersSet)) - assert.True(IsComponentFolder("archetypes")) - assert.True(IsComponentFolder("layouts")) - assert.True(IsComponentFolder("data")) - assert.True(IsComponentFolder("i18n")) - assert.True(IsComponentFolder("assets")) - assert.False(IsComponentFolder("resources")) - assert.True(IsComponentFolder("static")) - assert.True(IsComponentFolder("content")) - assert.False(IsComponentFolder("foo")) - assert.False(IsComponentFolder("")) + c.Assert(len(componentFoldersSet), qt.Equals, len(ComponentFolders)) + c.Assert(IsComponentFolder("archetypes"), qt.Equals, true) + c.Assert(IsComponentFolder("layouts"), qt.Equals, true) + c.Assert(IsComponentFolder("data"), qt.Equals, true) + c.Assert(IsComponentFolder("i18n"), qt.Equals, true) + c.Assert(IsComponentFolder("assets"), qt.Equals, true) + c.Assert(IsComponentFolder("resources"), qt.Equals, false) + c.Assert(IsComponentFolder("static"), qt.Equals, true) + c.Assert(IsComponentFolder("content"), qt.Equals, true) + c.Assert(IsComponentFolder("foo"), qt.Equals, false) + c.Assert(IsComponentFolder(""), qt.Equals, false) } diff --git a/hugofs/filter_fs_test.go b/hugofs/filter_fs_test.go index cc9a5e044..e3bf4c3b9 100644 --- a/hugofs/filter_fs_test.go +++ b/hugofs/filter_fs_test.go @@ -17,7 +17,7 @@ import ( "path/filepath" "testing" - "github.com/stretchr/testify/require" + qt "github.com/frankban/quicktest" ) func TestLangInfoFrom(t *testing.T) { @@ -27,7 +27,7 @@ func TestLangInfoFrom(t *testing.T) { "en": 20, } - assert := require.New(t) + c := qt.New(t) tests := []struct { input string @@ -42,7 +42,7 @@ func TestLangInfoFrom(t *testing.T) { for _, test := range tests { v1, v2, v3 := langInfoFrom(langs, test.input) - assert.Equal(test.expected, []string{v1, v2, v3}) + c.Assert([]string{v1, v2, v3}, qt.DeepEquals, test.expected) } } diff --git a/hugofs/fs_test.go b/hugofs/fs_test.go index 95900e6a2..47a9482f5 100644 --- a/hugofs/fs_test.go +++ b/hugofs/fs_test.go @@ -16,45 +16,46 @@ package hugofs import ( "testing" + qt "github.com/frankban/quicktest" + "github.com/gohugoio/hugo/htesting/hqt" "github.com/spf13/afero" "github.com/spf13/viper" - "github.com/stretchr/testify/assert" ) func TestNewDefault(t *testing.T) { + c := qt.New(t) v := viper.New() f := NewDefault(v) - assert.NotNil(t, f.Source) - assert.IsType(t, new(afero.OsFs), f.Source) - assert.NotNil(t, f.Destination) - assert.IsType(t, new(afero.OsFs), f.Destination) - assert.NotNil(t, f.Os) - assert.IsType(t, new(afero.OsFs), f.Os) - assert.Nil(t, f.WorkingDir) + c.Assert(f.Source, qt.Not(qt.IsNil)) + c.Assert(f.Source, hqt.IsSameType, new(afero.OsFs)) + c.Assert(f.Os, qt.Not(qt.IsNil)) + c.Assert(f.WorkingDir, qt.IsNil) - assert.IsType(t, new(afero.OsFs), Os) } func TestNewMem(t *testing.T) { + c := qt.New(t) v := viper.New() f := NewMem(v) - assert.NotNil(t, f.Source) - assert.IsType(t, new(afero.MemMapFs), f.Source) - assert.NotNil(t, f.Destination) - assert.IsType(t, new(afero.MemMapFs), f.Destination) - assert.IsType(t, new(afero.OsFs), f.Os) - assert.Nil(t, f.WorkingDir) + c.Assert(f.Source, qt.Not(qt.IsNil)) + c.Assert(f.Source, hqt.IsSameType, new(afero.MemMapFs)) + c.Assert(f.Destination, qt.Not(qt.IsNil)) + c.Assert(f.Destination, hqt.IsSameType, new(afero.MemMapFs)) + c.Assert(f.Os, hqt.IsSameType, new(afero.OsFs)) + c.Assert(f.WorkingDir, qt.IsNil) } func TestWorkingDir(t *testing.T) { + c := qt.New(t) v := viper.New() v.Set("workingDir", "/a/b/") f := NewMem(v) - assert.NotNil(t, f.WorkingDir) - assert.IsType(t, new(afero.BasePathFs), f.WorkingDir) + c.Assert(f.WorkingDir, qt.Not(qt.IsNil)) + c.Assert(f.WorkingDir, hqt.IsSameType, new(afero.BasePathFs)) + } diff --git a/hugofs/hashing_fs_test.go b/hugofs/hashing_fs_test.go index b690630ed..b2bfb78f4 100644 --- a/hugofs/hashing_fs_test.go +++ b/hugofs/hashing_fs_test.go @@ -16,8 +16,8 @@ package hugofs import ( "testing" + qt "github.com/frankban/quicktest" "github.com/spf13/afero" - "github.com/stretchr/testify/require" ) type testHashReceiver struct { @@ -31,23 +31,23 @@ func (t *testHashReceiver) OnFileClose(name, md5hash string) { } func TestHashingFs(t *testing.T) { - assert := require.New(t) + c := qt.New(t) fs := afero.NewMemMapFs() observer := &testHashReceiver{} ofs := NewHashingFs(fs, observer) f, err := ofs.Create("hashme") - assert.NoError(err) + c.Assert(err, qt.IsNil) _, err = f.Write([]byte("content")) - assert.NoError(err) - assert.NoError(f.Close()) - assert.Equal("9a0364b9e99bb480dd25e1f0284c8555", observer.sum) - assert.Equal("hashme", observer.name) + c.Assert(err, qt.IsNil) + c.Assert(f.Close(), qt.IsNil) + c.Assert(observer.sum, qt.Equals, "9a0364b9e99bb480dd25e1f0284c8555") + c.Assert(observer.name, qt.Equals, "hashme") f, err = ofs.Create("nowrites") - assert.NoError(err) - assert.NoError(f.Close()) - assert.Equal("d41d8cd98f00b204e9800998ecf8427e", observer.sum) + c.Assert(err, qt.IsNil) + c.Assert(f.Close(), qt.IsNil) + c.Assert(observer.sum, qt.Equals, "d41d8cd98f00b204e9800998ecf8427e") } diff --git a/hugofs/nosymlink_test.go b/hugofs/nosymlink_test.go index a04e671fc..b3b364789 100644 --- a/hugofs/nosymlink_test.go +++ b/hugofs/nosymlink_test.go @@ -24,28 +24,28 @@ import ( "github.com/spf13/afero" - "github.com/stretchr/testify/require" + qt "github.com/frankban/quicktest" ) func prepareSymlinks(t *testing.T) (string, func()) { - assert := require.New(t) + c := qt.New(t) workDir, clean, err := htesting.CreateTempDir(Os, "hugo-symlink-test") - assert.NoError(err) + c.Assert(err, qt.IsNil) wd, _ := os.Getwd() blogDir := filepath.Join(workDir, "blog") blogSubDir := filepath.Join(blogDir, "sub") - assert.NoError(os.MkdirAll(blogSubDir, 0777)) + c.Assert(os.MkdirAll(blogSubDir, 0777), qt.IsNil) blogFile1 := filepath.Join(blogDir, "a.txt") blogFile2 := filepath.Join(blogSubDir, "b.txt") afero.WriteFile(Os, filepath.Join(blogFile1), []byte("content1"), 0777) afero.WriteFile(Os, filepath.Join(blogFile2), []byte("content2"), 0777) os.Chdir(workDir) - assert.NoError(os.Symlink("blog", "symlinkdedir")) + c.Assert(os.Symlink("blog", "symlinkdedir"), qt.IsNil) os.Chdir(blogDir) - assert.NoError(os.Symlink("sub", "symsub")) - assert.NoError(os.Symlink("a.txt", "symlinkdedfile.txt")) + c.Assert(os.Symlink("sub", "symsub"), qt.IsNil) + c.Assert(os.Symlink("a.txt", "symlinkdedfile.txt"), qt.IsNil) return workDir, func() { clean() @@ -57,7 +57,7 @@ func TestNoSymlinkFs(t *testing.T) { if skipSymlink() { t.Skip("Skip; os.Symlink needs administrator rights on Windows") } - assert := require.New(t) + c := qt.New(t) workDir, clean := prepareSymlinks(t) defer clean() @@ -77,9 +77,9 @@ func TestNoSymlinkFs(t *testing.T) { assertFileErr := func(err error) { if allowFiles { - assert.NoError(err) + c.Assert(err, qt.IsNil) } else { - assert.Equal(ErrPermissionSymlink, err) + c.Assert(err, qt.Equals, ErrPermissionSymlink) } } @@ -87,8 +87,8 @@ func TestNoSymlinkFs(t *testing.T) { t.Helper() assertFileErr(err) if err == nil { - assert.NotNil(fi) - assert.Equal(name, fi.Name()) + c.Assert(fi, qt.Not(qt.IsNil)) + c.Assert(fi.Name(), qt.Equals, name) } } @@ -103,42 +103,42 @@ func TestNoSymlinkFs(t *testing.T) { }, } { _, err := stat(symlinkedDir) - assert.Equal(ErrPermissionSymlink, err) + c.Assert(err, qt.Equals, ErrPermissionSymlink) fi, err := stat(symlinkedFile) assertFileStat(symlinkedFilename, fi, err) fi, err = stat(filepath.Join(workDir, "blog")) - assert.NoError(err) - assert.NotNil(fi) + c.Assert(err, qt.IsNil) + c.Assert(fi, qt.Not(qt.IsNil)) fi, err = stat(blogFile1) - assert.NoError(err) - assert.NotNil(fi) + c.Assert(err, qt.IsNil) + c.Assert(fi, qt.Not(qt.IsNil)) } // Check Open _, err := fs.Open(symlinkedDir) - assert.Equal(ErrPermissionSymlink, err) + c.Assert(err, qt.Equals, ErrPermissionSymlink) _, err = fs.OpenFile(symlinkedDir, os.O_RDWR|os.O_APPEND|os.O_CREATE, 0666) - assert.Equal(ErrPermissionSymlink, err) + c.Assert(err, qt.Equals, ErrPermissionSymlink) _, err = fs.OpenFile(symlinkedFile, os.O_RDWR|os.O_APPEND|os.O_CREATE, 0666) assertFileErr(err) _, err = fs.Open(symlinkedFile) assertFileErr(err) f, err := fs.Open(blogDir) - assert.NoError(err) + c.Assert(err, qt.IsNil) f.Close() f, err = fs.Open(blogFile1) - assert.NoError(err) + c.Assert(err, qt.IsNil) f.Close() // Check readdir f, err = fs.Open(workDir) - assert.NoError(err) + c.Assert(err, qt.IsNil) // There is at least one unsported symlink inside workDir _, err = f.Readdir(-1) f.Close() - assert.Equal(uint64(1), logger.WarnCounter.Count()) + c.Assert(logger.WarnCounter.Count(), qt.Equals, uint64(1)) } } diff --git a/hugofs/rootmapping_fs_test.go b/hugofs/rootmapping_fs_test.go index 0b3f251f2..d2459167c 100644 --- a/hugofs/rootmapping_fs_test.go +++ b/hugofs/rootmapping_fs_test.go @@ -21,24 +21,24 @@ import ( "github.com/spf13/viper" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/htesting" "github.com/spf13/afero" - "github.com/stretchr/testify/require" ) func TestLanguageRootMapping(t *testing.T) { - assert := require.New(t) + c := qt.New(t) v := viper.New() v.Set("contentDir", "content") fs := NewBaseFileDecorator(afero.NewMemMapFs()) - assert.NoError(afero.WriteFile(fs, filepath.Join("content/sv/svdir", "main.txt"), []byte("main sv"), 0755)) - assert.NoError(afero.WriteFile(fs, filepath.Join("themes/a/mysvblogcontent", "sv-f.txt"), []byte("some sv blog content"), 0755)) - assert.NoError(afero.WriteFile(fs, filepath.Join("themes/a/myenblogcontent", "en-f.txt"), []byte("some en blog content in a"), 0755)) - assert.NoError(afero.WriteFile(fs, filepath.Join("themes/a/myotherenblogcontent", "en-f2.txt"), []byte("some en content"), 0755)) - assert.NoError(afero.WriteFile(fs, filepath.Join("themes/a/mysvdocs", "sv-docs.txt"), []byte("some sv docs content"), 0755)) - assert.NoError(afero.WriteFile(fs, filepath.Join("themes/b/myenblogcontent", "en-b-f.txt"), []byte("some en content"), 0755)) + c.Assert(afero.WriteFile(fs, filepath.Join("content/sv/svdir", "main.txt"), []byte("main sv"), 0755), qt.IsNil) + c.Assert(afero.WriteFile(fs, filepath.Join("themes/a/mysvblogcontent", "sv-f.txt"), []byte("some sv blog content"), 0755), qt.IsNil) + c.Assert(afero.WriteFile(fs, filepath.Join("themes/a/myenblogcontent", "en-f.txt"), []byte("some en blog content in a"), 0755), qt.IsNil) + c.Assert(afero.WriteFile(fs, filepath.Join("themes/a/myotherenblogcontent", "en-f2.txt"), []byte("some en content"), 0755), qt.IsNil) + c.Assert(afero.WriteFile(fs, filepath.Join("themes/a/mysvdocs", "sv-docs.txt"), []byte("some sv docs content"), 0755), qt.IsNil) + c.Assert(afero.WriteFile(fs, filepath.Join("themes/b/myenblogcontent", "en-b-f.txt"), []byte("some en content"), 0755), qt.IsNil) rfs, err := NewRootMappingFs(fs, RootMapping{ @@ -68,38 +68,38 @@ func TestLanguageRootMapping(t *testing.T) { }, ) - assert.NoError(err) + c.Assert(err, qt.IsNil) collected, err := collectFilenames(rfs, "content", "content") - assert.NoError(err) - assert.Equal([]string{"blog/en-f.txt", "blog/en-f2.txt", "blog/sv-f.txt", "blog/svdir/main.txt", "docs/sv-docs.txt"}, collected) + c.Assert(err, qt.IsNil) + c.Assert(collected, qt.DeepEquals, []string{"blog/en-f.txt", "blog/en-f2.txt", "blog/sv-f.txt", "blog/svdir/main.txt", "docs/sv-docs.txt"}) bfs := afero.NewBasePathFs(rfs, "content") collected, err = collectFilenames(bfs, "", "") - assert.NoError(err) - assert.Equal([]string{"blog/en-f.txt", "blog/en-f2.txt", "blog/sv-f.txt", "blog/svdir/main.txt", "docs/sv-docs.txt"}, collected) + c.Assert(err, qt.IsNil) + c.Assert(collected, qt.DeepEquals, []string{"blog/en-f.txt", "blog/en-f2.txt", "blog/sv-f.txt", "blog/svdir/main.txt", "docs/sv-docs.txt"}) dirs, err := rfs.Dirs(filepath.FromSlash("content/blog")) - assert.NoError(err) + c.Assert(err, qt.IsNil) - assert.Equal(4, len(dirs)) + c.Assert(len(dirs), qt.Equals, 4) getDirnames := func(name string, rfs *RootMappingFs) []string { filename := filepath.FromSlash(name) f, err := rfs.Open(filename) - assert.NoError(err) + c.Assert(err, qt.IsNil) names, err := f.Readdirnames(-1) f.Close() - assert.NoError(err) + c.Assert(err, qt.IsNil) info, err := rfs.Stat(filename) - assert.NoError(err) + c.Assert(err, qt.IsNil) f2, err := info.(FileMetaInfo).Meta().Open() - assert.NoError(err) + c.Assert(err, qt.IsNil) names2, err := f2.Readdirnames(-1) - assert.NoError(err) - assert.Equal(names, names2) + c.Assert(err, qt.IsNil) + c.Assert(names2, qt.DeepEquals, names) f2.Close() return names @@ -109,83 +109,83 @@ func TestLanguageRootMapping(t *testing.T) { return rm.Meta.Lang() == "en" }) - assert.Equal([]string{"en-f.txt", "en-f2.txt"}, getDirnames("content/blog", rfsEn)) + c.Assert(getDirnames("content/blog", rfsEn), qt.DeepEquals, []string{"en-f.txt", "en-f2.txt"}) rfsSv := rfs.Filter(func(rm RootMapping) bool { return rm.Meta.Lang() == "sv" }) - assert.Equal([]string{"sv-f.txt", "svdir"}, getDirnames("content/blog", rfsSv)) + c.Assert(getDirnames("content/blog", rfsSv), qt.DeepEquals, []string{"sv-f.txt", "svdir"}) // Make sure we have not messed with the original - assert.Equal([]string{"sv-f.txt", "en-f.txt", "svdir", "en-f2.txt"}, getDirnames("content/blog", rfs)) + c.Assert(getDirnames("content/blog", rfs), qt.DeepEquals, []string{"sv-f.txt", "en-f.txt", "svdir", "en-f2.txt"}) - assert.Equal([]string{"blog", "docs"}, getDirnames("content", rfsSv)) - assert.Equal([]string{"blog", "docs"}, getDirnames("content", rfs)) + c.Assert(getDirnames("content", rfsSv), qt.DeepEquals, []string{"blog", "docs"}) + c.Assert(getDirnames("content", rfs), qt.DeepEquals, []string{"blog", "docs"}) } func TestRootMappingFsDirnames(t *testing.T) { - assert := require.New(t) + c := qt.New(t) fs := NewBaseFileDecorator(afero.NewMemMapFs()) testfile := "myfile.txt" - assert.NoError(fs.Mkdir("f1t", 0755)) - assert.NoError(fs.Mkdir("f2t", 0755)) - assert.NoError(fs.Mkdir("f3t", 0755)) - assert.NoError(afero.WriteFile(fs, filepath.Join("f2t", testfile), []byte("some content"), 0755)) + c.Assert(fs.Mkdir("f1t", 0755), qt.IsNil) + c.Assert(fs.Mkdir("f2t", 0755), qt.IsNil) + c.Assert(fs.Mkdir("f3t", 0755), qt.IsNil) + c.Assert(afero.WriteFile(fs, filepath.Join("f2t", testfile), []byte("some content"), 0755), qt.IsNil) rfs, err := NewRootMappingFsFromFromTo(fs, "static/bf1", "f1t", "static/cf2", "f2t", "static/af3", "f3t") - assert.NoError(err) + c.Assert(err, qt.IsNil) fif, err := rfs.Stat(filepath.Join("static/cf2", testfile)) - assert.NoError(err) - assert.Equal("myfile.txt", fif.Name()) + c.Assert(err, qt.IsNil) + c.Assert(fif.Name(), qt.Equals, "myfile.txt") fifm := fif.(FileMetaInfo).Meta() - assert.Equal(filepath.FromSlash("f2t/myfile.txt"), fifm.Filename()) + c.Assert(fifm.Filename(), qt.Equals, filepath.FromSlash("f2t/myfile.txt")) root, err := rfs.Open(filepathSeparator) - assert.NoError(err) + c.Assert(err, qt.IsNil) dirnames, err := root.Readdirnames(-1) - assert.NoError(err) - assert.Equal([]string{"bf1", "cf2", "af3"}, dirnames) + c.Assert(err, qt.IsNil) + c.Assert(dirnames, qt.DeepEquals, []string{"bf1", "cf2", "af3"}) } func TestRootMappingFsFilename(t *testing.T) { - assert := require.New(t) + c := qt.New(t) workDir, clean, err := htesting.CreateTempDir(Os, "hugo-root-filename") - assert.NoError(err) + c.Assert(err, qt.IsNil) defer clean() fs := NewBaseFileDecorator(Os) testfilename := filepath.Join(workDir, "f1t/foo/file.txt") - assert.NoError(fs.MkdirAll(filepath.Join(workDir, "f1t/foo"), 0777)) - assert.NoError(afero.WriteFile(fs, testfilename, []byte("content"), 0666)) + c.Assert(fs.MkdirAll(filepath.Join(workDir, "f1t/foo"), 0777), qt.IsNil) + c.Assert(afero.WriteFile(fs, testfilename, []byte("content"), 0666), qt.IsNil) rfs, err := NewRootMappingFsFromFromTo(fs, "static/f1", filepath.Join(workDir, "f1t"), "static/f2", filepath.Join(workDir, "f2t")) - assert.NoError(err) + c.Assert(err, qt.IsNil) fi, err := rfs.Stat(filepath.FromSlash("static/f1/foo/file.txt")) - assert.NoError(err) + c.Assert(err, qt.IsNil) fim := fi.(FileMetaInfo) - assert.Equal(testfilename, fim.Meta().Filename()) + c.Assert(fim.Meta().Filename(), qt.Equals, testfilename) _, err = rfs.Stat(filepath.FromSlash("static/f1")) - assert.NoError(err) + c.Assert(err, qt.IsNil) } func TestRootMappingFsMount(t *testing.T) { - assert := require.New(t) + c := qt.New(t) fs := NewBaseFileDecorator(afero.NewMemMapFs()) testfile := "test.txt" - assert.NoError(afero.WriteFile(fs, filepath.Join("themes/a/mynoblogcontent", testfile), []byte("some no content"), 0755)) - assert.NoError(afero.WriteFile(fs, filepath.Join("themes/a/myenblogcontent", testfile), []byte("some en content"), 0755)) - assert.NoError(afero.WriteFile(fs, filepath.Join("themes/a/mysvblogcontent", testfile), []byte("some sv content"), 0755)) - assert.NoError(afero.WriteFile(fs, filepath.Join("themes/a/mysvblogcontent", "other.txt"), []byte("some sv content"), 0755)) + c.Assert(afero.WriteFile(fs, filepath.Join("themes/a/mynoblogcontent", testfile), []byte("some no content"), 0755), qt.IsNil) + c.Assert(afero.WriteFile(fs, filepath.Join("themes/a/myenblogcontent", testfile), []byte("some en content"), 0755), qt.IsNil) + c.Assert(afero.WriteFile(fs, filepath.Join("themes/a/mysvblogcontent", testfile), []byte("some sv content"), 0755), qt.IsNil) + c.Assert(afero.WriteFile(fs, filepath.Join("themes/a/mysvblogcontent", "other.txt"), []byte("some sv content"), 0755), qt.IsNil) bfs := afero.NewBasePathFs(fs, "themes/a").(*afero.BasePathFs) rm := []RootMapping{ @@ -204,48 +204,48 @@ func TestRootMappingFsMount(t *testing.T) { } rfs, err := NewRootMappingFs(bfs, rm...) - assert.NoError(err) + c.Assert(err, qt.IsNil) blog, err := rfs.Stat(filepath.FromSlash("content/blog")) - assert.NoError(err) + c.Assert(err, qt.IsNil) blogm := blog.(FileMetaInfo).Meta() - assert.Equal("sv", blogm.Lang()) // Last match + c.Assert(blogm.Lang(), qt.Equals, "sv") // Last match f, err := blogm.Open() - assert.NoError(err) + c.Assert(err, qt.IsNil) defer f.Close() dirs1, err := f.Readdirnames(-1) - assert.NoError(err) + c.Assert(err, qt.IsNil) // Union with duplicate dir names filtered. - assert.Equal([]string{"test.txt", "test.txt", "other.txt", "test.txt"}, dirs1) + c.Assert(dirs1, qt.DeepEquals, []string{"test.txt", "test.txt", "other.txt", "test.txt"}) files, err := afero.ReadDir(rfs, filepath.FromSlash("content/blog")) - assert.NoError(err) - assert.Equal(4, len(files)) + c.Assert(err, qt.IsNil) + c.Assert(len(files), qt.Equals, 4) testfilefi := files[1] - assert.Equal(testfile, testfilefi.Name()) + c.Assert(testfilefi.Name(), qt.Equals, testfile) testfilem := testfilefi.(FileMetaInfo).Meta() - assert.Equal(filepath.FromSlash("themes/a/mynoblogcontent/test.txt"), testfilem.Filename()) + c.Assert(testfilem.Filename(), qt.Equals, filepath.FromSlash("themes/a/mynoblogcontent/test.txt")) tf, err := testfilem.Open() - assert.NoError(err) + c.Assert(err, qt.IsNil) defer tf.Close() - c, err := ioutil.ReadAll(tf) - assert.NoError(err) - assert.Equal("some no content", string(c)) + b, err := ioutil.ReadAll(tf) + c.Assert(err, qt.IsNil) + c.Assert(string(b), qt.Equals, "some no content") } func TestRootMappingFsMountOverlap(t *testing.T) { - assert := require.New(t) + c := qt.New(t) fs := NewBaseFileDecorator(afero.NewMemMapFs()) - assert.NoError(afero.WriteFile(fs, filepath.FromSlash("da/a.txt"), []byte("some no content"), 0755)) - assert.NoError(afero.WriteFile(fs, filepath.FromSlash("db/b.txt"), []byte("some no content"), 0755)) - assert.NoError(afero.WriteFile(fs, filepath.FromSlash("dc/c.txt"), []byte("some no content"), 0755)) - assert.NoError(afero.WriteFile(fs, filepath.FromSlash("de/e.txt"), []byte("some no content"), 0755)) + c.Assert(afero.WriteFile(fs, filepath.FromSlash("da/a.txt"), []byte("some no content"), 0755), qt.IsNil) + c.Assert(afero.WriteFile(fs, filepath.FromSlash("db/b.txt"), []byte("some no content"), 0755), qt.IsNil) + c.Assert(afero.WriteFile(fs, filepath.FromSlash("dc/c.txt"), []byte("some no content"), 0755), qt.IsNil) + c.Assert(afero.WriteFile(fs, filepath.FromSlash("de/e.txt"), []byte("some no content"), 0755), qt.IsNil) rm := []RootMapping{ RootMapping{ @@ -267,56 +267,56 @@ func TestRootMappingFsMountOverlap(t *testing.T) { } rfs, err := NewRootMappingFs(fs, rm...) - assert.NoError(err) + c.Assert(err, qt.IsNil) getDirnames := func(name string) []string { name = filepath.FromSlash(name) f, err := rfs.Open(name) - assert.NoError(err) + c.Assert(err, qt.IsNil) defer f.Close() names, err := f.Readdirnames(-1) - assert.NoError(err) + c.Assert(err, qt.IsNil) return names } - assert.Equal([]string{"a.txt", "b", "e"}, getDirnames("static")) - assert.Equal([]string{"b.txt", "c"}, getDirnames("static/b")) - assert.Equal([]string{"c.txt"}, getDirnames("static/b/c")) + c.Assert(getDirnames("static"), qt.DeepEquals, []string{"a.txt", "b", "e"}) + c.Assert(getDirnames("static/b"), qt.DeepEquals, []string{"b.txt", "c"}) + c.Assert(getDirnames("static/b/c"), qt.DeepEquals, []string{"c.txt"}) fi, err := rfs.Stat(filepath.FromSlash("static/b/b.txt")) - assert.NoError(err) - assert.Equal("b.txt", fi.Name()) + c.Assert(err, qt.IsNil) + c.Assert(fi.Name(), qt.Equals, "b.txt") } func TestRootMappingFsOs(t *testing.T) { - assert := require.New(t) + c := qt.New(t) fs := afero.NewOsFs() d, err := ioutil.TempDir("", "hugo-root-mapping") - assert.NoError(err) + c.Assert(err, qt.IsNil) defer func() { os.RemoveAll(d) }() testfile := "myfile.txt" - assert.NoError(fs.Mkdir(filepath.Join(d, "f1t"), 0755)) - assert.NoError(fs.Mkdir(filepath.Join(d, "f2t"), 0755)) - assert.NoError(fs.Mkdir(filepath.Join(d, "f3t"), 0755)) - assert.NoError(afero.WriteFile(fs, filepath.Join(d, "f2t", testfile), []byte("some content"), 0755)) + c.Assert(fs.Mkdir(filepath.Join(d, "f1t"), 0755), qt.IsNil) + c.Assert(fs.Mkdir(filepath.Join(d, "f2t"), 0755), qt.IsNil) + c.Assert(fs.Mkdir(filepath.Join(d, "f3t"), 0755), qt.IsNil) + c.Assert(afero.WriteFile(fs, filepath.Join(d, "f2t", testfile), []byte("some content"), 0755), qt.IsNil) rfs, err := NewRootMappingFsFromFromTo(fs, "static/bf1", filepath.Join(d, "f1t"), "static/cf2", filepath.Join(d, "f2t"), "static/af3", filepath.Join(d, "f3t")) - assert.NoError(err) + c.Assert(err, qt.IsNil) fif, err := rfs.Stat(filepath.Join("static/cf2", testfile)) - assert.NoError(err) - assert.Equal("myfile.txt", fif.Name()) + c.Assert(err, qt.IsNil) + c.Assert(fif.Name(), qt.Equals, "myfile.txt") root, err := rfs.Open(filepathSeparator) - assert.NoError(err) + c.Assert(err, qt.IsNil) dirnames, err := root.Readdirnames(-1) - assert.NoError(err) - assert.Equal([]string{"bf1", "cf2", "af3"}, dirnames) + c.Assert(err, qt.IsNil) + c.Assert(dirnames, qt.DeepEquals, []string{"bf1", "cf2", "af3"}) } diff --git a/hugofs/walk_test.go b/hugofs/walk_test.go index d492041ae..4effa8000 100644 --- a/hugofs/walk_test.go +++ b/hugofs/walk_test.go @@ -29,11 +29,11 @@ import ( "github.com/spf13/afero" - "github.com/stretchr/testify/require" + qt "github.com/frankban/quicktest" ) func TestWalk(t *testing.T) { - assert := require.New(t) + c := qt.New(t) fs := NewBaseFileDecorator(afero.NewMemMapFs()) @@ -43,19 +43,19 @@ func TestWalk(t *testing.T) { names, err := collectFilenames(fs, "", "") - assert.NoError(err) - assert.Equal([]string{"a.txt", "b.txt", "c.txt"}, names) + c.Assert(err, qt.IsNil) + c.Assert(names, qt.DeepEquals, []string{"a.txt", "b.txt", "c.txt"}) } func TestWalkRootMappingFs(t *testing.T) { - assert := require.New(t) + c := qt.New(t) fs := NewBaseFileDecorator(afero.NewMemMapFs()) testfile := "test.txt" - assert.NoError(afero.WriteFile(fs, filepath.Join("a/b", testfile), []byte("some content"), 0755)) - assert.NoError(afero.WriteFile(fs, filepath.Join("c/d", testfile), []byte("some content"), 0755)) - assert.NoError(afero.WriteFile(fs, filepath.Join("e/f", testfile), []byte("some content"), 0755)) + c.Assert(afero.WriteFile(fs, filepath.Join("a/b", testfile), []byte("some content"), 0755), qt.IsNil) + c.Assert(afero.WriteFile(fs, filepath.Join("c/d", testfile), []byte("some content"), 0755), qt.IsNil) + c.Assert(afero.WriteFile(fs, filepath.Join("e/f", testfile), []byte("some content"), 0755), qt.IsNil) rm := []RootMapping{ RootMapping{ @@ -74,13 +74,13 @@ func TestWalkRootMappingFs(t *testing.T) { } rfs, err := NewRootMappingFs(fs, rm...) - assert.NoError(err) + c.Assert(err, qt.IsNil) bfs := afero.NewBasePathFs(rfs, "static") names, err := collectFilenames(bfs, "", "") - assert.NoError(err) - assert.Equal([]string{"a/test.txt", "b/test.txt", "c/test.txt"}, names) + c.Assert(err, qt.IsNil) + c.Assert(names, qt.DeepEquals, []string{"a/test.txt", "b/test.txt", "c/test.txt"}) } @@ -92,9 +92,9 @@ func TestWalkSymbolicLink(t *testing.T) { if skipSymlink() { t.Skip("Skip; os.Symlink needs administrator rights on Windows") } - assert := require.New(t) + c := qt.New(t) workDir, clean, err := htesting.CreateTempDir(Os, "hugo-walk-sym") - assert.NoError(err) + c.Assert(err, qt.IsNil) defer clean() wd, _ := os.Getwd() defer func() { @@ -107,25 +107,25 @@ func TestWalkSymbolicLink(t *testing.T) { docsDir := filepath.Join(workDir, "docs") blogReal := filepath.Join(blogDir, "real") blogRealSub := filepath.Join(blogReal, "sub") - assert.NoError(os.MkdirAll(blogRealSub, 0777)) - assert.NoError(os.MkdirAll(docsDir, 0777)) + c.Assert(os.MkdirAll(blogRealSub, 0777), qt.IsNil) + c.Assert(os.MkdirAll(docsDir, 0777), qt.IsNil) afero.WriteFile(fs, filepath.Join(blogRealSub, "a.txt"), []byte("content"), 0777) afero.WriteFile(fs, filepath.Join(docsDir, "b.txt"), []byte("content"), 0777) os.Chdir(blogDir) - assert.NoError(os.Symlink("real", "symlinked")) + c.Assert(os.Symlink("real", "symlinked"), qt.IsNil) os.Chdir(blogReal) - assert.NoError(os.Symlink("../real", "cyclic")) + c.Assert(os.Symlink("../real", "cyclic"), qt.IsNil) os.Chdir(docsDir) - assert.NoError(os.Symlink("../blog/real/cyclic", "docsreal")) |