add readfile e2e test

Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
yxxhero
2022-05-24 07:50:08 +08:00
committed by yxxhero
parent 70b874a596
commit 33c66a6f46
7 changed files with 44 additions and 3 deletions
+9
View File
@@ -5,3 +5,12 @@ type Context struct {
basePath string
readFile func(string) ([]byte, error)
}
// SetBasePath sets the base path for the template
func (c *Context) SetBasePath(path string) {
c.basePath = path
}
func (c *Context) SetReadFile(f func(string) ([]byte, error)) {
c.readFile = f
}
+4
View File
@@ -172,6 +172,10 @@ func (c *Context) ReadFile(filename string) (string, error) {
path = filepath.Join(c.basePath, filename)
}
if c.readFile == nil {
return "", fmt.Errorf("readFile is not implemented")
}
bytes, err := c.readFile(path)
if err != nil {
return "", err