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{ | 		Context: &Context{ | ||||||
| 			basePath: basePath, | 			basePath: basePath, | ||||||
| 			readFile: readFile, | 			readFile: readFile, | ||||||
|  | 			readDir:  os.ReadDir, | ||||||
| 		}, | 		}, | ||||||
| 		Data: data, | 		Data: data, | ||||||
| 	} | 	} | ||||||
|  | @ -31,6 +32,7 @@ func NewFirstPassRenderer(basePath string, data interface{}) *FileRenderer { | ||||||
| 			preRender: true, | 			preRender: true, | ||||||
| 			basePath:  basePath, | 			basePath:  basePath, | ||||||
| 			readFile:  os.ReadFile, | 			readFile:  os.ReadFile, | ||||||
|  | 			readDir:   os.ReadDir, | ||||||
| 		}, | 		}, | ||||||
| 		Data: data, | 		Data: data, | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -2,6 +2,7 @@ package helmfile | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"bytes" | 	"bytes" | ||||||
|  | 	"fmt" | ||||||
| 	"os" | 	"os" | ||||||
| 	"testing" | 	"testing" | ||||||
| 	"text/template" | 	"text/template" | ||||||
|  | @ -264,6 +265,31 @@ func (t *tmplE2e) load() { | ||||||
| 
 | 
 | ||||||
| var tmplE2eTest = tmplE2e{} | 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
 | // TestTmplStrings tests the template string
 | ||||||
| func TestTmplStrings(t *testing.T) { | func TestTmplStrings(t *testing.T) { | ||||||
| 	c := &tmpl.Context{} | 	c := &tmpl.Context{} | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue