filesystem

package
v1.8.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2017 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultFs

type DefaultFs struct{}

DefaultFs implements Filesystem using same-named functions from "os" and "io/ioutil"

func (DefaultFs) Chtimes

func (DefaultFs) Chtimes(name string, atime time.Time, mtime time.Time) error

Chtimes via os.Chtimes

func (DefaultFs) Create

func (DefaultFs) Create(name string) (File, error)

Create via os.Create

func (DefaultFs) MkdirAll

func (DefaultFs) MkdirAll(path string, perm os.FileMode) error

MkdirAll via os.MkdirAll

func (DefaultFs) ReadFile

func (DefaultFs) ReadFile(filename string) ([]byte, error)

ReadFile via os.ReadFile

func (DefaultFs) Rename

func (DefaultFs) Rename(oldpath, newpath string) error

Rename via os.Rename

func (DefaultFs) Stat

func (DefaultFs) Stat(name string) (os.FileInfo, error)

Stat via os.Stat

func (DefaultFs) TempFile

func (DefaultFs) TempFile(dir, prefix string) (File, error)

TempFile via os.TempFile

type File

type File interface {
	// for now, the only os.File methods used are those below, add more as necessary
	Name() string
	Write(b []byte) (n int, err error)
	Close() error
}

File is an interface that we can use to mock various filesystem operations typically accessed through the File object from the "os" package

type Filesystem

type Filesystem interface {
	// from "os"
	Stat(name string) (os.FileInfo, error)
	Create(name string) (File, error)
	Rename(oldpath, newpath string) error
	MkdirAll(path string, perm os.FileMode) error
	Chtimes(name string, atime time.Time, mtime time.Time) error

	// from "io/ioutil"
	ReadFile(filename string) ([]byte, error)
	TempFile(dir, prefix string) (File, error)
}

Filesystem is an interface that we can use to mock various filesystem operations

func NewFakeFs

func NewFakeFs() Filesystem

NewFakeFs returns a fake Filesystem that exists in-memory, useful for unit tests

Jump to

Keyboard shortcuts

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