filesystem

package
v3.0.0-beta.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsCloseFileError

func IsCloseFileError(err error) bool

IsCloseFileError checks if the returned error is because the file could not be closed

func IsCreateDirectoryError

func IsCreateDirectoryError(err error) bool

IsCreateDirectoryError checks if the returned error is because the directory could not be created

func IsCreateFileError

func IsCreateFileError(err error) bool

IsCreateFileError checks if the returned error is because the file could not be created

func IsFileExistsError

func IsFileExistsError(err error) bool

IsFileExistsError checks if the returned error is because the file could not be checked for existence

func IsOpenFileError

func IsOpenFileError(err error) bool

IsOpenFileError checks if the returned error is because the file could not be opened

func IsReadFileError

func IsReadFileError(err error) bool

IsReadFileError checks if the returned error is because the file could not be read

func IsWriteFileError

func IsWriteFileError(err error) bool

IsWriteFileError checks if the returned error is because the file could not be written to

Types

type FileSystem

type FileSystem interface {
	// Exists checks if the file exists
	Exists(path string) (bool, error)

	// Open opens the file and returns a self-closing io.Reader.
	Open(path string) (io.ReadCloser, error)

	// Create creates the directory and file and returns a self-closing
	// io.Writer pointing to that file. If the file exists, it truncates it.
	Create(path string) (io.Writer, error)
}

FileSystem is an IO wrapper to create files

func New

func New(options ...Options) FileSystem

New returns a new FileSystem

func NewMock

func NewMock(options ...MockOptions) FileSystem

NewMock returns a new FileSystem

type MockOptions

type MockOptions func(system *mockFileSystem)

MockOptions configure FileSystem

func MockCloseFileError

func MockCloseFileError(err error) MockOptions

MockCloseFileError makes the Write method (of the io.Writer returned by FileSystem.Create) return err

func MockCreateDirError

func MockCreateDirError(err error) MockOptions

MockCreateDirError makes FileSystem.Create return err

func MockCreateFileError

func MockCreateFileError(err error) MockOptions

MockCreateFileError makes FileSystem.Create return err

func MockExists

func MockExists(exists func(path string) bool) MockOptions

MockExists makes FileSystem.Exists use the provided function to check if the file exists

func MockExistsError

func MockExistsError(err error) MockOptions

MockExistsError makes FileSystem.Exists return err

func MockInput

func MockInput(input *bytes.Buffer) MockOptions

MockInput provides a buffer where the content will be read from

func MockOpenFileError

func MockOpenFileError(err error) MockOptions

MockOpenFileError makes FileSystem.Open return err

func MockOutput

func MockOutput(output *bytes.Buffer) MockOptions

MockOutput provides a buffer where the content will be written

func MockPath

func MockPath(path string) MockOptions

MockPath ensures that the file created with this scaffold is at path

func MockReadFileError

func MockReadFileError(err error) MockOptions

MockReadFileError makes the Read method (of the io.Reader returned by FileSystem.Open) return err

func MockWriteFileError

func MockWriteFileError(err error) MockOptions

MockWriteFileError makes the Write method (of the io.Writer returned by FileSystem.Create) return err

type Options

type Options func(system *fileSystem)

Options configure FileSystem

func DirectoryPermissions

func DirectoryPermissions(dirPerm os.FileMode) Options

DirectoryPermissions makes FileSystem.Create use the provided directory permissions

func FilePermissions

func FilePermissions(filePerm os.FileMode) Options

FilePermissions makes FileSystem.Create use the provided file permissions

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL