Documentation
¶
Overview ¶
Package fs provides tools for creating and working with temporary files and directories.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dir ¶
type Dir struct {
// contains filtered or unexported fields
}
Dir is a temporary directory
func NewDir ¶
NewDir returns a new temporary directory using prefix as part of the directory name. The PathOps are applied before returning the Dir.
Example ¶
Create a temporary directory which contains a single file
dir := NewDir(t, "test-name", WithFile("file1", "content\n")) defer dir.Remove() files, err := ioutil.ReadDir(dir.Path()) require.NoError(t, err) assert.Len(t, files, 0)
type File ¶
type File struct {
// contains filtered or unexported fields
}
File is a temporary file on the filesystem
func NewFile ¶
NewFile creates a new file in a temporary directory using prefix as part of the filename. The PathOps are applied to the before returning the File.
Example ¶
Create a new file with some content
file := NewFile(t, "test-name", WithContent("content\n"), AsUser(0, 0)) defer file.Remove() content, err := ioutil.ReadFile(file.Path()) require.NoError(t, err) assert.Equal(t, "content\n", content)
type Path ¶
type Path interface {
Path() string
}
Path objects return their filesystem path. Both File and Dir implement Path.
type PathOp ¶
PathOp is a function which accepts a Path to perform some operation
func WithContent ¶
WithContent writes content to a file at Path