github.com/hairyhenderson/templater@v3.5.0+incompatible/template_unix_test.go (about) 1 // +build !windows 2 3 package gomplate 4 5 import ( 6 "testing" 7 8 "github.com/spf13/afero" 9 10 "github.com/stretchr/testify/assert" 11 ) 12 13 func TestWalkDir(t *testing.T) { 14 origfs := fs 15 defer func() { fs = origfs }() 16 fs = afero.NewMemMapFs() 17 18 _, err := walkDir("/indir", simpleNamer("/outdir"), nil, 0, false) 19 assert.Error(t, err) 20 21 _ = fs.MkdirAll("/indir/one", 0777) 22 _ = fs.MkdirAll("/indir/two", 0777) 23 afero.WriteFile(fs, "/indir/one/foo", []byte("foo"), 0644) 24 afero.WriteFile(fs, "/indir/one/bar", []byte("bar"), 0664) 25 afero.WriteFile(fs, "/indir/two/baz", []byte("baz"), 0644) 26 27 templates, err := walkDir("/indir", simpleNamer("/outdir"), []string{"*/two"}, 0, false) 28 29 assert.NoError(t, err) 30 expected := []*tplate{ 31 { 32 name: "/indir/one/bar", 33 targetPath: "/outdir/one/bar", 34 mode: 0664, 35 }, 36 { 37 name: "/indir/one/foo", 38 targetPath: "/outdir/one/foo", 39 mode: 0644, 40 }, 41 } 42 assert.EqualValues(t, expected, templates) 43 }