github.com/hairyhenderson/gomplate/v3@v3.11.7/template_unix_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, "/indir", simpleNamer("/outdir"), nil, 0, false)
    24  	assert.Error(t, err)
    25  
    26  	_ = aferoFS.MkdirAll("/indir/one", 0o777)
    27  	_ = aferoFS.MkdirAll("/indir/two", 0o777)
    28  	afero.WriteFile(aferoFS, "/indir/one/foo", []byte("foo"), 0o644)
    29  	afero.WriteFile(aferoFS, "/indir/one/bar", []byte("bar"), 0o664)
    30  	afero.WriteFile(aferoFS, "/indir/two/baz", []byte("baz"), 0o644)
    31  
    32  	templates, err := walkDir(ctx, cfg, "/indir", simpleNamer("/outdir"), []string{"*/two"}, 0, false)
    33  
    34  	assert.NoError(t, err)
    35  	expected := []Template{
    36  		{
    37  			Name: "/indir/one/bar",
    38  			Text: "bar",
    39  		},
    40  		{
    41  			Name: "/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  }