"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "hugofs/walk_test.go" between
hugo-0.85.0.tar.gz and hugo-0.86.0.tar.gz

About: Hugo is a static site generator that takes a source directory of Markdown files and templates and uses these as input to create a complete website (written in Go).

walk_test.go  (hugo-0.85.0):walk_test.go  (hugo-0.86.0)
skipping to change at line 17 skipping to change at line 17
// //
// Unless required by applicable law or agreed to in writing, software // Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, // distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package hugofs package hugofs
import ( import (
"context"
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strings" "strings"
"testing" "testing"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/gohugoio/hugo/common/para"
"github.com/gohugoio/hugo/htesting" "github.com/gohugoio/hugo/htesting"
"github.com/spf13/afero" "github.com/spf13/afero"
qt "github.com/frankban/quicktest" qt "github.com/frankban/quicktest"
) )
func TestWalk(t *testing.T) { func TestWalk(t *testing.T) {
c := qt.New(t) c := qt.New(t)
skipping to change at line 50 skipping to change at line 52
afero.WriteFile(fs, "a.txt", []byte("content"), 0777) afero.WriteFile(fs, "a.txt", []byte("content"), 0777)
names, err := collectFilenames(fs, "", "") names, err := collectFilenames(fs, "", "")
c.Assert(err, qt.IsNil) c.Assert(err, qt.IsNil)
c.Assert(names, qt.DeepEquals, []string{"a.txt", "b.txt", "c.txt"}) c.Assert(names, qt.DeepEquals, []string{"a.txt", "b.txt", "c.txt"})
} }
func TestWalkRootMappingFs(t *testing.T) { func TestWalkRootMappingFs(t *testing.T) {
c := qt.New(t) c := qt.New(t)
fs := NewBaseFileDecorator(afero.NewMemMapFs())
testfile := "test.txt" prepare := func(c *qt.C) afero.Fs {
fs := NewBaseFileDecorator(afero.NewMemMapFs())
testfile := "test.txt"
c.Assert(afero.WriteFile(fs, filepath.Join("a/b", testfile), []byte("some c.Assert(afero.WriteFile(fs, filepath.Join("a/b", testfile), []by
content"), 0755), qt.IsNil) te("some content"), 0755), qt.IsNil)
c.Assert(afero.WriteFile(fs, filepath.Join("c/d", testfile), []byte("some c.Assert(afero.WriteFile(fs, filepath.Join("c/d", testfile), []by
content"), 0755), qt.IsNil) te("some content"), 0755), qt.IsNil)
c.Assert(afero.WriteFile(fs, filepath.Join("e/f", testfile), []byte("some c.Assert(afero.WriteFile(fs, filepath.Join("e/f", testfile), []by
content"), 0755), qt.IsNil) te("some content"), 0755), qt.IsNil)
rm := []RootMapping{ rm := []RootMapping{
{ {
From: "static/b", From: "static/b",
To: "e/f", To: "e/f",
}, },
{ {
From: "static/a", From: "static/a",
To: "c/d", To: "c/d",
}, },
{ {
From: "static/c", From: "static/c",
To: "a/b", To: "a/b",
}, },
}
rfs, err := NewRootMappingFs(fs, rm...)
c.Assert(err, qt.IsNil)
return afero.NewBasePathFs(rfs, "static")
} }
rfs, err := NewRootMappingFs(fs, rm...) c.Run("Basic", func(c *qt.C) {
c.Assert(err, qt.IsNil)
bfs := afero.NewBasePathFs(rfs, "static")
names, err := collectFilenames(bfs, "", "") bfs := prepare(c)
c.Assert(err, qt.IsNil) names, err := collectFilenames(bfs, "", "")
c.Assert(names, qt.DeepEquals, []string{"a/test.txt", "b/test.txt", "c/te
st.txt"}) c.Assert(err, qt.IsNil)
c.Assert(names, qt.DeepEquals, []string{"a/test.txt", "b/test.txt
", "c/test.txt"})
})
c.Run("Para", func(c *qt.C) {
bfs := prepare(c)
p := para.New(4)
r, _ := p.Start(context.Background())
for i := 0; i < 8; i++ {
r.Run(func() error {
_, err := collectFilenames(bfs, "", "")
if err != nil {
return err
}
fi, err := bfs.Stat("b/test.txt")
if err != nil {
return err
}
meta := fi.(FileMetaInfo).Meta()
if meta.Filename == "" {
return errors.New("fail")
}
return nil
})
}
c.Assert(r.Wait(), qt.IsNil)
})
} }
func skipSymlink() bool { func skipSymlink() bool {
if runtime.GOOS != "windows" { if runtime.GOOS != "windows" {
return false return false
} }
if os.Getenv("GITHUB_ACTION") != "" { if os.Getenv("GITHUB_ACTION") != "" {
// TODO(bep) figure out why this fails on GitHub Actions. // TODO(bep) figure out why this fails on GitHub Actions.
return true return true
} }
skipping to change at line 160 skipping to change at line 200
walkFn := func(path string, info FileMetaInfo, err error) error { walkFn := func(path string, info FileMetaInfo, err error) error {
if err != nil { if err != nil {
return err return err
} }
if info.IsDir() { if info.IsDir() {
return nil return nil
} }
filename := info.Meta().Path() filename := info.Meta().Path
filename = filepath.ToSlash(filename) filename = filepath.ToSlash(filename)
names = append(names, filename) names = append(names, filename)
return nil return nil
} }
w := NewWalkway(WalkwayConfig{Fs: fs, BasePath: base, Root: root, WalkFn: walkFn}) w := NewWalkway(WalkwayConfig{Fs: fs, BasePath: base, Root: root, WalkFn: walkFn})
err := w.Walk() err := w.Walk()
skipping to change at line 224 skipping to change at line 264
writeFiles("root/l1_3", numFilesPerDir) writeFiles("root/l1_3", numFilesPerDir)
walkFn := func(path string, info FileMetaInfo, err error) error { walkFn := func(path string, info FileMetaInfo, err error) error {
if err != nil { if err != nil {
return err return err
} }
if info.IsDir() { if info.IsDir() {
return nil return nil
} }
filename := info.Meta().Filename() filename := info.Meta().Filename
if !strings.HasPrefix(filename, "root") { if !strings.HasPrefix(filename, "root") {
return errors.New(filename) return errors.New(filename)
} }
return nil return nil
} }
b.ResetTimer() b.ResetTimer()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
w := NewWalkway(WalkwayConfig{Fs: fs, Root: "root", WalkFn: walkF n}) w := NewWalkway(WalkwayConfig{Fs: fs, Root: "root", WalkFn: walkF n})
 End of changes. 10 change blocks. 
32 lines changed or deleted 72 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)