Documentation
¶
Overview ¶
Package testfs provides a simple fs.FS which is contained in a test (using testing.TB's TempDir) and with a few helper methods.
The temporary FS is auto-cleaned once the test and all its children finish.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrOutsideFS = fmt.Errorf("path is outside test fs root folder")
ErrOutsideFS happens when the user tries to handle files outside of the FS's root path.
Functions ¶
This section is empty.
Types ¶
type FS ¶ added in v0.3.0
FS is a fs.FS made for testing only.
func New ¶ added in v0.2.0
New creates a new FS using the tb.TempDir as root.
Example ¶
tmpfs := New(&testing.T{}) _ = tmpfs.MkdirAll("foo/bar", 0o764) _ = tmpfs.WriteFile("foo/bar/foobar", []byte("example"), 0o644) bts, _ := fs.ReadFile(tmpfs, "foo/bar/foobar") fmt.Println(string(bts))
Output: example
func (FS) MkdirAll ¶ added in v0.3.0
MkdirAll creates the dir and all the necessary parents into FS.
Click to show internal directories.
Click to hide internal directories.