terraform/configs/parser_test.go

32 lines
702 B
Go
Raw Normal View History

package configs
import (
"os"
"path"
"github.com/spf13/afero"
)
// testParser returns a parser that reads files from the given map, which
// is from paths to file contents.
//
// Since this function uses only in-memory objects, it should never fail.
// If any errors are encountered in practice, this function will panic.
func testParser(files map[string]string) *Parser {
fs := afero.Afero{Fs: afero.NewMemMapFs()}
for filePath, contents := range files {
dirPath := path.Dir(filePath)
err := fs.MkdirAll(dirPath, os.ModePerm)
if err != nil {
panic(err)
}
err = fs.WriteFile(filePath, []byte(contents), os.ModePerm)
if err != nil {
panic(err)
}
}
return NewParser(fs)
}