"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "hugofs/rootmapping_fs_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).

rootmapping_fs_test.go  (hugo-0.85.0):rootmapping_fs_test.go  (hugo-0.86.0)
skipping to change at line 52 skipping to change at line 52
c.Assert(afero.WriteFile(fs, filepath.Join("themes/a/myenblogcontent/d1", "en-d1-f.txt"), []byte("some en blog content in a"), 0755), qt.IsNil) c.Assert(afero.WriteFile(fs, filepath.Join("themes/a/myenblogcontent/d1", "en-d1-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/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/a/mysvdocs", "sv-docs. txt"), []byte("some sv docs content"), 0755), qt.IsNil)
c.Assert(afero.WriteFile(fs, filepath.Join("themes/b/myenblogcontent", "e n-b-f.txt"), []byte("some en content"), 0755), qt.IsNil) c.Assert(afero.WriteFile(fs, filepath.Join("themes/b/myenblogcontent", "e n-b-f.txt"), []byte("some en content"), 0755), qt.IsNil)
rfs, err := NewRootMappingFs(fs, rfs, err := NewRootMappingFs(fs,
RootMapping{ RootMapping{
From: "content/blog", // Virtual path, first element is one of content, static, layouts etc. From: "content/blog", // Virtual path, first element is one of content, static, layouts etc.
To: "themes/a/mysvblogcontent", // Real path To: "themes/a/mysvblogcontent", // Real path
Meta: FileMeta{"lang": "sv"}, Meta: &FileMeta{Lang: "sv"},
}, },
RootMapping{ RootMapping{
From: "content/blog", From: "content/blog",
To: "themes/a/myenblogcontent", To: "themes/a/myenblogcontent",
Meta: FileMeta{"lang": "en"}, Meta: &FileMeta{Lang: "en"},
}, },
RootMapping{ RootMapping{
From: "content/blog", From: "content/blog",
To: "content/sv", To: "content/sv",
Meta: FileMeta{"lang": "sv"}, Meta: &FileMeta{Lang: "sv"},
}, },
RootMapping{ RootMapping{
From: "content/blog", From: "content/blog",
To: "themes/a/myotherenblogcontent", To: "themes/a/myotherenblogcontent",
Meta: FileMeta{"lang": "en"}, Meta: &FileMeta{Lang: "en"},
}, },
RootMapping{ RootMapping{
From: "content/docs", From: "content/docs",
To: "themes/a/mysvdocs", To: "themes/a/mysvdocs",
Meta: FileMeta{"lang": "sv"}, Meta: &FileMeta{Lang: "sv"},
}, },
) )
c.Assert(err, qt.IsNil) c.Assert(err, qt.IsNil)
collected, err := collectFilenames(rfs, "content", "content") collected, err := collectFilenames(rfs, "content", "content")
c.Assert(err, qt.IsNil) c.Assert(err, qt.IsNil)
c.Assert(collected, qt.DeepEquals, c.Assert(collected, qt.DeepEquals,
[]string{"blog/d1/en-d1-f.txt", "blog/d1/sv-d1-f.txt", "blog/en-f .txt", "blog/en-f2.txt", "blog/sv-f.txt", "blog/svdir/main.txt", "docs/sv-docs.t xt"}, qt.Commentf("%#v", collected)) []string{"blog/d1/en-d1-f.txt", "blog/d1/sv-d1-f.txt", "blog/en-f .txt", "blog/en-f2.txt", "blog/sv-f.txt", "blog/svdir/main.txt", "docs/sv-docs.t xt"}, qt.Commentf("%#v", collected))
skipping to change at line 125 skipping to change at line 125
c.Assert(err, qt.IsNil) c.Assert(err, qt.IsNil)
names2, err := f2.Readdirnames(-1) names2, err := f2.Readdirnames(-1)
c.Assert(err, qt.IsNil) c.Assert(err, qt.IsNil)
c.Assert(names2, qt.DeepEquals, names) c.Assert(names2, qt.DeepEquals, names)
f2.Close() f2.Close()
return names return names
} }
rfsEn := rfs.Filter(func(rm RootMapping) bool { rfsEn := rfs.Filter(func(rm RootMapping) bool {
return rm.Meta.Lang() == "en" return rm.Meta.Lang == "en"
}) })
c.Assert(getDirnames("content/blog", rfsEn), qt.DeepEquals, []string{"d1" , "en-f.txt", "en-f2.txt"}) c.Assert(getDirnames("content/blog", rfsEn), qt.DeepEquals, []string{"d1" , "en-f.txt", "en-f2.txt"})
rfsSv := rfs.Filter(func(rm RootMapping) bool { rfsSv := rfs.Filter(func(rm RootMapping) bool {
return rm.Meta.Lang() == "sv" return rm.Meta.Lang == "sv"
}) })
c.Assert(getDirnames("content/blog", rfsSv), qt.DeepEquals, []string{"d1" , "sv-f.txt", "svdir"}) c.Assert(getDirnames("content/blog", rfsSv), qt.DeepEquals, []string{"d1" , "sv-f.txt", "svdir"})
// Make sure we have not messed with the original // Make sure we have not messed with the original
c.Assert(getDirnames("content/blog", rfs), qt.DeepEquals, []string{"d1", "sv-f.txt", "en-f.txt", "svdir", "en-f2.txt"}) c.Assert(getDirnames("content/blog", rfs), qt.DeepEquals, []string{"d1", "sv-f.txt", "en-f.txt", "svdir", "en-f2.txt"})
c.Assert(getDirnames("content", rfsSv), qt.DeepEquals, []string{"blog", " docs"}) c.Assert(getDirnames("content", rfsSv), qt.DeepEquals, []string{"blog", " docs"})
c.Assert(getDirnames("content", rfs), qt.DeepEquals, []string{"blog", "do cs"}) c.Assert(getDirnames("content", rfs), qt.DeepEquals, []string{"blog", "do cs"})
} }
skipping to change at line 160 skipping to change at line 160
c.Assert(fs.Mkdir("f3t", 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) c.Assert(afero.WriteFile(fs, filepath.Join("f2t", testfile), []byte("some content"), 0755), qt.IsNil)
rfs, err := newRootMappingFsFromFromTo("", fs, "static/bf1", "f1t", "stat ic/cf2", "f2t", "static/af3", "f3t") rfs, err := newRootMappingFsFromFromTo("", fs, "static/bf1", "f1t", "stat ic/cf2", "f2t", "static/af3", "f3t")
c.Assert(err, qt.IsNil) c.Assert(err, qt.IsNil)
fif, err := rfs.Stat(filepath.Join("static/cf2", testfile)) fif, err := rfs.Stat(filepath.Join("static/cf2", testfile))
c.Assert(err, qt.IsNil) c.Assert(err, qt.IsNil)
c.Assert(fif.Name(), qt.Equals, "myfile.txt") c.Assert(fif.Name(), qt.Equals, "myfile.txt")
fifm := fif.(FileMetaInfo).Meta() fifm := fif.(FileMetaInfo).Meta()
c.Assert(fifm.Filename(), qt.Equals, filepath.FromSlash("f2t/myfile.txt") ) c.Assert(fifm.Filename, qt.Equals, filepath.FromSlash("f2t/myfile.txt"))
root, err := rfs.Open("static") root, err := rfs.Open("static")
c.Assert(err, qt.IsNil) c.Assert(err, qt.IsNil)
dirnames, err := root.Readdirnames(-1) dirnames, err := root.Readdirnames(-1)
c.Assert(err, qt.IsNil) c.Assert(err, qt.IsNil)
c.Assert(dirnames, qt.DeepEquals, []string{"af3", "bf1", "cf2"}) c.Assert(dirnames, qt.DeepEquals, []string{"af3", "bf1", "cf2"})
} }
func TestRootMappingFsFilename(t *testing.T) { func TestRootMappingFsFilename(t *testing.T) {
skipping to change at line 188 skipping to change at line 188
c.Assert(fs.MkdirAll(filepath.Join(workDir, "f1t/foo"), 0777), qt.IsNil) c.Assert(fs.MkdirAll(filepath.Join(workDir, "f1t/foo"), 0777), qt.IsNil)
c.Assert(afero.WriteFile(fs, testfilename, []byte("content"), 0666), qt.I sNil) c.Assert(afero.WriteFile(fs, testfilename, []byte("content"), 0666), qt.I sNil)
rfs, err := newRootMappingFsFromFromTo(workDir, fs, "static/f1", filepath .Join(workDir, "f1t"), "static/f2", filepath.Join(workDir, "f2t")) rfs, err := newRootMappingFsFromFromTo(workDir, fs, "static/f1", filepath .Join(workDir, "f1t"), "static/f2", filepath.Join(workDir, "f2t"))
c.Assert(err, qt.IsNil) c.Assert(err, qt.IsNil)
fi, err := rfs.Stat(filepath.FromSlash("static/f1/foo/file.txt")) fi, err := rfs.Stat(filepath.FromSlash("static/f1/foo/file.txt"))
c.Assert(err, qt.IsNil) c.Assert(err, qt.IsNil)
fim := fi.(FileMetaInfo) fim := fi.(FileMetaInfo)
c.Assert(fim.Meta().Filename(), qt.Equals, testfilename) c.Assert(fim.Meta().Filename, qt.Equals, testfilename)
_, err = rfs.Stat(filepath.FromSlash("static/f1")) _, err = rfs.Stat(filepath.FromSlash("static/f1"))
c.Assert(err, qt.IsNil) c.Assert(err, qt.IsNil)
} }
func TestRootMappingFsMount(t *testing.T) { func TestRootMappingFsMount(t *testing.T) {
c := qt.New(t) c := qt.New(t)
fs := NewBaseFileDecorator(afero.NewMemMapFs()) fs := NewBaseFileDecorator(afero.NewMemMapFs())
testfile := "test.txt" testfile := "test.txt"
skipping to change at line 212 skipping to change at line 212
c.Assert(afero.WriteFile(fs, filepath.Join("themes/a/mysvblogcontent", "o ther.txt"), []byte("some sv content"), 0755), qt.IsNil) c.Assert(afero.WriteFile(fs, filepath.Join("themes/a/mysvblogcontent", "o ther.txt"), []byte("some sv content"), 0755), qt.IsNil)
c.Assert(afero.WriteFile(fs, filepath.Join("themes/a/singlefiles", "no.tx t"), []byte("no text"), 0755), qt.IsNil) c.Assert(afero.WriteFile(fs, filepath.Join("themes/a/singlefiles", "no.tx t"), []byte("no text"), 0755), qt.IsNil)
c.Assert(afero.WriteFile(fs, filepath.Join("themes/a/singlefiles", "sv.tx t"), []byte("sv text"), 0755), qt.IsNil) c.Assert(afero.WriteFile(fs, filepath.Join("themes/a/singlefiles", "sv.tx t"), []byte("sv text"), 0755), qt.IsNil)
bfs := afero.NewBasePathFs(fs, "themes/a").(*afero.BasePathFs) bfs := afero.NewBasePathFs(fs, "themes/a").(*afero.BasePathFs)
rm := []RootMapping{ rm := []RootMapping{
// Directories // Directories
{ {
From: "content/blog", From: "content/blog",
To: "mynoblogcontent", To: "mynoblogcontent",
Meta: FileMeta{"lang": "no"}, Meta: &FileMeta{Lang: "no"},
}, },
{ {
From: "content/blog", From: "content/blog",
To: "myenblogcontent", To: "myenblogcontent",
Meta: FileMeta{"lang": "en"}, Meta: &FileMeta{Lang: "en"},
}, },
{ {
From: "content/blog", From: "content/blog",
To: "mysvblogcontent", To: "mysvblogcontent",
Meta: FileMeta{"lang": "sv"}, Meta: &FileMeta{Lang: "sv"},
}, },
// Files // Files
{ {
From: "content/singles/p1.md", From: "content/singles/p1.md",
To: "singlefiles/no.txt", To: "singlefiles/no.txt",
ToBasedir: "singlefiles", ToBasedir: "singlefiles",
Meta: FileMeta{"lang": "no"}, Meta: &FileMeta{Lang: "no"},
}, },
{ {
From: "content/singles/p1.md", From: "content/singles/p1.md",
To: "singlefiles/sv.txt", To: "singlefiles/sv.txt",
ToBasedir: "singlefiles", ToBasedir: "singlefiles",
Meta: FileMeta{"lang": "sv"}, Meta: &FileMeta{Lang: "sv"},
}, },
} }
rfs, err := NewRootMappingFs(bfs, rm...) rfs, err := NewRootMappingFs(bfs, rm...)
c.Assert(err, qt.IsNil) c.Assert(err, qt.IsNil)
blog, err := rfs.Stat(filepath.FromSlash("content/blog")) blog, err := rfs.Stat(filepath.FromSlash("content/blog"))
c.Assert(err, qt.IsNil) c.Assert(err, qt.IsNil)
c.Assert(blog.IsDir(), qt.Equals, true) c.Assert(blog.IsDir(), qt.Equals, true)
blogm := blog.(FileMetaInfo).Meta() blogm := blog.(FileMetaInfo).Meta()
c.Assert(blogm.Lang(), qt.Equals, "no") // First match c.Assert(blogm.Lang, qt.Equals, "no") // First match
f, err := blogm.Open() f, err := blogm.Open()
c.Assert(err, qt.IsNil) c.Assert(err, qt.IsNil)
defer f.Close() defer f.Close()
dirs1, err := f.Readdirnames(-1) dirs1, err := f.Readdirnames(-1)
c.Assert(err, qt.IsNil) c.Assert(err, qt.IsNil)
// Union with duplicate dir names filtered. // Union with duplicate dir names filtered.
c.Assert(dirs1, qt.DeepEquals, []string{"test.txt", "test.txt", "other.tx t", "test.txt"}) c.Assert(dirs1, qt.DeepEquals, []string{"test.txt", "test.txt", "other.tx t", "test.txt"})
files, err := afero.ReadDir(rfs, filepath.FromSlash("content/blog")) files, err := afero.ReadDir(rfs, filepath.FromSlash("content/blog"))
c.Assert(err, qt.IsNil) c.Assert(err, qt.IsNil)
c.Assert(len(files), qt.Equals, 4) c.Assert(len(files), qt.Equals, 4)
testfilefi := files[1] testfilefi := files[1]
c.Assert(testfilefi.Name(), qt.Equals, testfile) c.Assert(testfilefi.Name(), qt.Equals, testfile)
testfilem := testfilefi.(FileMetaInfo).Meta() testfilem := testfilefi.(FileMetaInfo).Meta()
c.Assert(testfilem.Filename(), qt.Equals, filepath.FromSlash("themes/a/my noblogcontent/test.txt")) c.Assert(testfilem.Filename, qt.Equals, filepath.FromSlash("themes/a/myno blogcontent/test.txt"))
tf, err := testfilem.Open() tf, err := testfilem.Open()
c.Assert(err, qt.IsNil) c.Assert(err, qt.IsNil)
defer tf.Close() defer tf.Close()
b, err := ioutil.ReadAll(tf) b, err := ioutil.ReadAll(tf)
c.Assert(err, qt.IsNil) c.Assert(err, qt.IsNil)
c.Assert(string(b), qt.Equals, "some no content") c.Assert(string(b), qt.Equals, "some no content")
// Ambiguous // Ambiguous
_, err = rfs.Stat(filepath.FromSlash("content/singles/p1.md")) _, err = rfs.Stat(filepath.FromSlash("content/singles/p1.md"))
skipping to change at line 286 skipping to change at line 286
singlesDir, err := rfs.Open(filepath.FromSlash("content/singles")) singlesDir, err := rfs.Open(filepath.FromSlash("content/singles"))
c.Assert(err, qt.IsNil) c.Assert(err, qt.IsNil)
defer singlesDir.Close() defer singlesDir.Close()
singles, err := singlesDir.Readdir(-1) singles, err := singlesDir.Readdir(-1)
c.Assert(err, qt.IsNil) c.Assert(err, qt.IsNil)
c.Assert(singles, qt.HasLen, 2) c.Assert(singles, qt.HasLen, 2)
for i, lang := range []string{"no", "sv"} { for i, lang := range []string{"no", "sv"} {
fi := singles[i].(FileMetaInfo) fi := singles[i].(FileMetaInfo)
c.Assert(fi.Meta().PathFile(), qt.Equals, filepath.FromSlash("the mes/a/singlefiles/"+lang+".txt")) c.Assert(fi.Meta().PathFile(), qt.Equals, filepath.FromSlash("the mes/a/singlefiles/"+lang+".txt"))
c.Assert(fi.Meta().Lang(), qt.Equals, lang) c.Assert(fi.Meta().Lang, qt.Equals, lang)
c.Assert(fi.Name(), qt.Equals, "p1.md") c.Assert(fi.Name(), qt.Equals, "p1.md")
} }
} }
func TestRootMappingFsMountOverlap(t *testing.T) { func TestRootMappingFsMountOverlap(t *testing.T) {
c := qt.New(t) c := qt.New(t)
fs := NewBaseFileDecorator(afero.NewMemMapFs()) fs := NewBaseFileDecorator(afero.NewMemMapFs())
c.Assert(afero.WriteFile(fs, filepath.FromSlash("da/a.txt"), []byte("some no content"), 0755), qt.IsNil) 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("db/b.txt"), []byte("some no content"), 0755), qt.IsNil)
skipping to change at line 434 skipping to change at line 434
fileInfos, err := f.Readdir(-1) fileInfos, err := f.Readdir(-1)
c.Assert(err, qt.IsNil) c.Assert(err, qt.IsNil)
sortFileInfos(fileInfos) sortFileInfos(fileInfos)
i := 0 i := 0
for _, fi := range fileInfos { for _, fi := range fileInfos {
if fi.IsDir() || fi.Name() == "ms-1.txt" { if fi.IsDir() || fi.Name() == "ms-1.txt" {
continue continue
} }
i++ i++
meta := fi.(FileMetaInfo).Meta() meta := fi.(FileMetaInfo).Meta()
c.Assert(meta.Filename(), qt.Equals, filepath.Join(d, fmt.Sprintf ("/d1/d2/d3/f-%d.txt", i))) c.Assert(meta.Filename, qt.Equals, filepath.Join(d, fmt.Sprintf(" /d1/d2/d3/f-%d.txt", i)))
c.Assert(meta.PathFile(), qt.Equals, filepath.FromSlash(fmt.Sprin tf("d1/d2/d3/f-%d.txt", i))) c.Assert(meta.PathFile(), qt.Equals, filepath.FromSlash(fmt.Sprin tf("d1/d2/d3/f-%d.txt", i)))
} }
_, err = rfs.Stat(filepath.FromSlash("layouts/d2/d3/f-1.txt")) _, err = rfs.Stat(filepath.FromSlash("layouts/d2/d3/f-1.txt"))
c.Assert(err, qt.IsNil) c.Assert(err, qt.IsNil)
_, err = rfs.Stat(filepath.FromSlash("layouts/d2/d3")) _, err = rfs.Stat(filepath.FromSlash("layouts/d2/d3"))
c.Assert(err, qt.IsNil) c.Assert(err, qt.IsNil)
} }
func TestRootMappingFsOsBase(t *testing.T) { func TestRootMappingFsOsBase(t *testing.T) {
 End of changes. 18 change blocks. 
18 lines changed or deleted 18 lines changed or added

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