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

      func NewDir(t require.TestingT, prefix string, ops ...PathOp) *Dir

        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

          Output:
          
          

          func (*Dir) Join

          func (d *Dir) Join(parts ...string) string

            Join returns a new path with this directory as the base of the path

            func (*Dir) Path

            func (d *Dir) Path() string

              Path returns the full path to the directory

              func (*Dir) Remove

              func (d *Dir) Remove()

                Remove the directory

                type File

                type File struct {
                	// contains filtered or unexported fields
                }

                  File is a temporary file on the filesystem

                  func NewFile

                  func NewFile(t require.TestingT, prefix string, ops ...PathOp) *File

                    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

                      Output:
                      
                      

                      func (*File) Path

                      func (f *File) Path() string

                        Path returns the full path to the file

                        func (*File) Remove

                        func (f *File) Remove()

                          Remove the file

                          type Path

                          type Path interface {
                          	Path() string
                          }

                            Path objects return their filesystem path. Both File and Dir implement Path.

                            type PathOp

                            type PathOp func(path Path) error

                              PathOp is a function which accepts a Path to perform some operation

                              func AsUser

                              func AsUser(uid, gid int) PathOp

                                AsUser changes ownership of the file system object at Path

                                func FromDir

                                func FromDir(source string) PathOp

                                  FromDir copies the directory tree from the source path into the new Dir

                                  func WithBytes

                                  func WithBytes(raw []byte) PathOp

                                    WithBytes write bytes to a file at Path

                                    func WithContent

                                    func WithContent(content string) PathOp

                                      WithContent writes content to a file at Path

                                      func WithFile

                                      func WithFile(filename, content string) PathOp

                                        WithFile creates a file in the directory at path with content

                                        func WithFiles

                                        func WithFiles(files map[string]string) PathOp

                                          WithFiles creates all the files in the directory at path with their content

                                          Source Files