Documentation ¶
Overview ¶
Package templatetest exposes a mock fs.FS that implements basic file operations. Used in unit tests for the purposes of avoiding the use of testdata/ directories when unit testing template rendering.
Cribbed from Mark Bates: https://www.gopherguides.com/articles/golang-1.16-io-fs-improve-test-performance
Index ¶
- func NewParser(tmpls ...FileMocker) *template.Parser
- type FileMocker
- type MockFS
- type MockFile
- func (m *MockFile) Close() error
- func (m *MockFile) Info() (fs.FileInfo, error)
- func (m *MockFile) IsDir() bool
- func (m *MockFile) ModTime() time.Time
- func (m *MockFile) Mode() os.FileMode
- func (m *MockFile) Name() string
- func (m *MockFile) Read(p []byte) (int, error)
- func (m *MockFile) Size() int64
- func (m *MockFile) Stat() (fs.FileInfo, error)
- func (m *MockFile) Sys() any
- func (m *MockFile) Type() fs.FileMode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewParser ¶
func NewParser(tmpls ...FileMocker) *template.Parser
NewParser constructs a *template.Parser with the mocked files.
Types ¶
type MockFS ¶
type MockFS []FileMocker
func NewMockFS ¶
func NewMockFS(tmpls ...FileMocker) MockFS
func (MockFS) Glob ¶
Glob checks whether the pattern matches the file after removing all directory paths from the respective parts.
Buyer beware: Glob is a simplistic implementation of fs.GlobFS.
i.e., pattern: some/long/path/* will match all of the following - some/long/path/myfile.txt - some/long/otherfile.txt - totally/different/tree/somefile.txt - /rootfile.txt ... etc.
type MockFile ¶
type MockFile struct { FS MockFS // contains filtered or unexported fields }