mock

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2023 License: Unlicense Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Time            = TimeFunc()
	UUID            = UUIDFunc()
	FS   FileSystem = MockFS()
)

Functions

func Mock

func Mock(fsOpts ...FSOption)

Mock re-initializes all mock variables to their mocked counterparts. FSOptions may be used to setup directories and files.

func TimeFunc

func TimeFunc() func() (t time.Time)

TimeFunc returns a new function which when called always returns the zero value of time.Time.

func UUIDFunc

func UUIDFunc() func() (uuid.UUID, error)

UUIDFunc returns a new function that will create deterministic but still unique IDs.

Types

type FSOption

type FSOption func(*FakeFileSystem)

func WithDirectory

func WithDirectory(path string) FSOption

func WithFile

func WithFile(path string, data []byte) FSOption

type FakeFile

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

type FakeFileDescriptor

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

func (*FakeFileDescriptor) Close

func (m *FakeFileDescriptor) Close() error

func (*FakeFileDescriptor) Info

func (m *FakeFileDescriptor) Info() (fs.FileInfo, error)

func (*FakeFileDescriptor) IsDir

func (m *FakeFileDescriptor) IsDir() bool

func (*FakeFileDescriptor) ModTime

func (m *FakeFileDescriptor) ModTime() time.Time

func (*FakeFileDescriptor) Mode

func (m *FakeFileDescriptor) Mode() fs.FileMode

func (*FakeFileDescriptor) Name

func (m *FakeFileDescriptor) Name() string

func (*FakeFileDescriptor) Read

func (m *FakeFileDescriptor) Read(b []byte) (n int, err error)

func (*FakeFileDescriptor) Seek

func (m *FakeFileDescriptor) Seek(offset int64, whence int) (int64, error)

func (*FakeFileDescriptor) Size

func (m *FakeFileDescriptor) Size() int64

func (*FakeFileDescriptor) Stat

func (m *FakeFileDescriptor) Stat() (fs.FileInfo, error)

func (*FakeFileDescriptor) Sys

func (m *FakeFileDescriptor) Sys() any

func (*FakeFileDescriptor) Type

func (m *FakeFileDescriptor) Type() fs.FileMode

func (*FakeFileDescriptor) Write

func (m *FakeFileDescriptor) Write(src []byte) (n int, err error)

type FakeFileSystem

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

func MockFS

func MockFS(opts ...FSOption) (fs *FakeFileSystem)

func (*FakeFileSystem) Create

func (m *FakeFileSystem) Create(path string) (File, error)

func (*FakeFileSystem) Open

func (m *FakeFileSystem) Open(path string) (File, error)

func (*FakeFileSystem) OpenFile

func (m *FakeFileSystem) OpenFile(path string, flag int, perm os.FileMode) (File, error)

func (*FakeFileSystem) ReadFile

func (m *FakeFileSystem) ReadFile(path string) ([]byte, error)

func (*FakeFileSystem) Remove

func (m *FakeFileSystem) Remove(path string) error

func (*FakeFileSystem) RemoveAll

func (m *FakeFileSystem) RemoveAll(path string) error

func (*FakeFileSystem) Stat

func (m *FakeFileSystem) Stat(path string) (fs.FileInfo, error)

func (*FakeFileSystem) String

func (m *FakeFileSystem) String() (pp string)

func (*FakeFileSystem) Truncate

func (m *FakeFileSystem) Truncate(path string, size int64) error

func (*FakeFileSystem) WalkDir

func (m *FakeFileSystem) WalkDir(root string, fn fs.WalkDirFunc) (err error)

func (*FakeFileSystem) WriteFile

func (m *FakeFileSystem) WriteFile(path string, data []byte, perm os.FileMode) error

type File

type File interface {
	Close() error
	Name() string
	Stat() (os.FileInfo, error)
	Read(b []byte) (n int, err error)                     // go doc os.File.Read
	Write(b []byte) (n int, err error)                    // go doc os.File.Write
	Seek(offset int64, whence int) (ret int64, err error) // go doc os.File.Seek
}

type FileSystem

type FileSystem interface {
	Create(path string) (File, error)
	Open(path string) (File, error)
	Stat(path string) (os.FileInfo, error)
	OpenFile(path string, flag int, perm fs.FileMode) (File, error)
	// @todo: Mkdir(name string, perm FileMode) error
	// @todo: MkdirAll(path string, perm FileMode) error
	WalkDir(root string, fn fs.WalkDirFunc) error
	Truncate(path string, size int64) error
	ReadFile(path string) ([]byte, error)
	WriteFile(path string, data []byte, perm os.FileMode) error
	Remove(path string) error
	RemoveAll(path string) error
}

type RealFileSystem

type RealFileSystem struct{}

func (*RealFileSystem) Create

func (*RealFileSystem) Create(path string) (File, error)

func (*RealFileSystem) Open

func (*RealFileSystem) Open(path string) (File, error)

func (*RealFileSystem) OpenFile

func (*RealFileSystem) OpenFile(path string, flag int, perm os.FileMode) (File, error)

func (*RealFileSystem) ReadFile

func (*RealFileSystem) ReadFile(path string) ([]byte, error)

func (*RealFileSystem) Remove

func (*RealFileSystem) Remove(path string) error

func (*RealFileSystem) RemoveAll

func (*RealFileSystem) RemoveAll(path string) error

func (*RealFileSystem) Stat

func (*RealFileSystem) Stat(path string) (fs.FileInfo, error)

func (*RealFileSystem) Truncate

func (*RealFileSystem) Truncate(path string, size int64) error

func (*RealFileSystem) WalkDir

func (*RealFileSystem) WalkDir(root string, fn fs.WalkDirFunc) error

func (*RealFileSystem) WriteFile

func (*RealFileSystem) WriteFile(path string, data []byte, perm os.FileMode) error

Jump to

Keyboard shortcuts

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