Merge pull request #297 from arkaitzj/FixForReadDir
Fix for readDir selection, currently any template that uses readDir* functions seems to break
This commit is contained in:
commit
c26bc2e26e
|
|
@ -19,6 +19,7 @@ func NewFileRenderer(readFile func(filename string) ([]byte, error), basePath st
|
|||
Context: &Context{
|
||||
basePath: basePath,
|
||||
readFile: readFile,
|
||||
readDir: os.ReadDir,
|
||||
},
|
||||
Data: data,
|
||||
}
|
||||
|
|
@ -31,6 +32,7 @@ func NewFirstPassRenderer(basePath string, data interface{}) *FileRenderer {
|
|||
preRender: true,
|
||||
basePath: basePath,
|
||||
readFile: os.ReadFile,
|
||||
readDir: os.ReadDir,
|
||||
},
|
||||
Data: data,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package helmfile
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
"text/template"
|
||||
|
|
@ -264,6 +265,31 @@ func (t *tmplE2e) load() {
|
|||
|
||||
var tmplE2eTest = tmplE2e{}
|
||||
|
||||
func TestFileRendering(t *testing.T) {
|
||||
tmplE2eTest.load()
|
||||
|
||||
for _, tc := range tmplE2eTest.tcs {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
tc.setEnvs(t)
|
||||
tempDir, _ := os.MkdirTemp("./testdata", "test")
|
||||
defer os.RemoveAll(tempDir)
|
||||
|
||||
filename := fmt.Sprintf("%s/%s.gotmpl", tempDir, tc.name)
|
||||
os.WriteFile(filename, []byte(tc.tmplString), 0644)
|
||||
fileRenderer := tmpl.NewFileRenderer(os.ReadFile, ".", tc.data)
|
||||
tmpl_bytes, err := fileRenderer.RenderToBytes(filename)
|
||||
|
||||
if tc.wantErr {
|
||||
require.Error(t, err)
|
||||
} else {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
tmpl := string(tmpl_bytes)
|
||||
require.Equal(t, tc.output, tmpl)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestTmplStrings tests the template string
|
||||
func TestTmplStrings(t *testing.T) {
|
||||
c := &tmpl.Context{}
|
||||
|
|
|
|||
Loading…
Reference in New Issue