github.com/hairyhenderson/gomplate/v3@v3.11.7/template_windows_test.go (about) 1 //go:build windows 2 3 package gomplate 4 5 import ( 6 "context" 7 "testing" 8 9 "github.com/hairyhenderson/gomplate/v3/internal/config" 10 "github.com/spf13/afero" 11 12 "github.com/stretchr/testify/assert" 13 ) 14 15 func TestWalkDir(t *testing.T) { 16 ctx := context.Background() 17 origfs := aferoFS 18 defer func() { aferoFS = origfs }() 19 aferoFS = afero.NewMemMapFs() 20 21 cfg := &config.Config{} 22 23 _, err := walkDir(ctx, cfg, `C:\indir`, simpleNamer(`C:\outdir`), nil, 0, false) 24 assert.Error(t, err) 25 26 _ = aferoFS.MkdirAll(`C:\indir\one`, 0o777) 27 _ = aferoFS.MkdirAll(`C:\indir\two`, 0o777) 28 afero.WriteFile(aferoFS, `C:\indir\one\foo`, []byte("foo"), 0o644) 29 afero.WriteFile(aferoFS, `C:\indir\one\bar`, []byte("bar"), 0o644) 30 afero.WriteFile(aferoFS, `C:\indir\two\baz`, []byte("baz"), 0o644) 31 32 templates, err := walkDir(ctx, cfg, `C:\indir`, simpleNamer(`C:\outdir`), []string{`*\two`}, 0, false) 33 34 assert.NoError(t, err) 35 expected := []Template{ 36 { 37 Name: `C:\indir\one\bar`, 38 Text: "bar", 39 }, 40 { 41 Name: `C:\indir\one\foo`, 42 Text: "foo", 43 }, 44 } 45 assert.Len(t, templates, 2) 46 for i, tmpl := range templates { 47 assert.Equal(t, expected[i].Name, tmpl.Name) 48 assert.Equal(t, expected[i].Text, tmpl.Text) 49 } 50 }