gofs

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: MIT Imports: 13 Imported by: 0

README

Yet another file system mock library in go

Features:

  • performance in non mock path (no interfaces)
  • profound testing (we use property based tsting to ensure simularity with real implementation)

Non features:

  • make a variety of different backends (NetFS, google cloud, s3, etc.). I try to keep this package as clean from dependencies as possible
  • simulating of concurrent effect of filesystem (e.g. concurrent ReadDir with file removing in different goroutine)

TODO:

  • Document what fileMode are supported
  • O_APPEND
  • Fallocate?
  • copy paste docs from orig functions
  • Test relative paths
  • add mode there instead on std error we get stacktrace inside error?
  • add thread safe fs?
  • add benchmark to track allocation
  • make good readme file
  • try to add fuzzing (and try to introduce errors)
  • add example of extension (compressed reader?)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeError

func MakeError(op string, path string, text string) error

func MakeWrappedError

func MakeWrappedError(op string, path string, err error) error

func NewInfoDataFromNode

func NewInfoDataFromNode(inode *mockData, name string) *infoData

Types

type Entry

type Entry interface {
	os.FileInfo
	os.DirEntry
}

TODO: do I use this?

type FS

type FS interface {
	Create(name string) (*File, error)
	CreateTemp(dir, pattern string) (*File, error)
	// NewFile(fd uintptr, name string) *File // TODO: ???
	Open(name string) (*File, error)
	OpenFile(name string, flag int, perm os.FileMode) (*File, error)
	Chdir(dir string) error
	Chmod(name string, mode os.FileMode) error
	Chown(name string, uid, gid int) error
	Mkdir(name string, perm os.FileMode) error
	MkdirAll(path string, perm os.FileMode) error
	MkdirTemp(dir, pattern string) (string, error)
	ReadFile(name string) ([]byte, error)
	Readlink(name string) (string, error)
	ReadDir(name string) ([]os.DirEntry, error)
	Remove(name string) error
	RemoveAll(path string) error
	Rename(oldpath, newpath string) error
	Truncate(name string, size int64) error
	WriteFile(name string, data []byte, perm os.FileMode) error
	Stat(name string) (os.FileInfo, error)
}

func OsFs

func OsFs() FS

type FakeFS

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

func NewMemoryFs

func NewMemoryFs() *FakeFS

func (*FakeFS) Chdir

func (f *FakeFS) Chdir(dir string) error

func (*FakeFS) Chmod

func (f *FakeFS) Chmod(name string, mode os.FileMode) error

func (*FakeFS) Chown

func (f *FakeFS) Chown(name string, uid, gid int) error

func (*FakeFS) CorruptDirtyPages

func (f *FakeFS) CorruptDirtyPages(seedRand *rand.Rand)

This function will probably changed by v1.0

func (*FakeFS) CorruptFile

func (f *FakeFS) CorruptFile(path string, offset int64) error

This function will probably changed by v1.0

func (*FakeFS) Create

func (f *FakeFS) Create(path string) (*File, error)

func (*FakeFS) CreateTemp

func (f *FakeFS) CreateTemp(dir, pattern string) (*File, error)

func (*FakeFS) Mkdir

func (f *FakeFS) Mkdir(name string, perm os.FileMode) error

func (*FakeFS) MkdirAll

func (f *FakeFS) MkdirAll(path string, perm os.FileMode) error

func (*FakeFS) MkdirTemp

func (f *FakeFS) MkdirTemp(dir, pattern string) (string, error)

func (*FakeFS) Open

func (f *FakeFS) Open(name string) (*File, error)

func (*FakeFS) OpenFile

func (f *FakeFS) OpenFile(name string, flag int, perm os.FileMode) (*File, error)

func (*FakeFS) ReadDir

func (f *FakeFS) ReadDir(name string) ([]os.DirEntry, error)

func (*FakeFS) ReadFile

func (f *FakeFS) ReadFile(name string) ([]byte, error)
func (f *FakeFS) Readlink(name string) (string, error)

func (*FakeFS) Release

func (f *FakeFS) Release()

Release return all memory to pool and clear file map. All File structs should be destroyed by this moment, accessing them is UB. This function is useful, for example in end of a test

func (*FakeFS) Remove

func (f *FakeFS) Remove(name string) error

func (*FakeFS) RemoveAll

func (f *FakeFS) RemoveAll(path string) error

func (*FakeFS) Rename

func (f *FakeFS) Rename(oldpath, newpath string) error

func (*FakeFS) Stat

func (f *FakeFS) Stat(name string) (os.FileInfo, error)

func (*FakeFS) Truncate

func (f *FakeFS) Truncate(name string, size int64) error

func (*FakeFS) WriteFile

func (f *FakeFS) WriteFile(name string, data []byte, perm os.FileMode) error

type FakeFile

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

Kinda like descriptor

func (*FakeFile) Chdir

func (f *FakeFile) Chdir() error

func (*FakeFile) Chmod

func (f *FakeFile) Chmod(mode os.FileMode) error

func (*FakeFile) Chown

func (f *FakeFile) Chown(uid, gid int) error

func (*FakeFile) Close

func (f *FakeFile) Close() error

func (*FakeFile) Name

func (f *FakeFile) Name() string

func (*FakeFile) Read

func (f *FakeFile) Read(b []byte) (n int, err error)

func (*FakeFile) ReadAt

func (f *FakeFile) ReadAt(b []byte, off int64) (n int, err error)

func (*FakeFile) ReadDir

func (f *FakeFile) ReadDir(n int) ([]os.DirEntry, error)

func (*FakeFile) ReadFrom

func (f *FakeFile) ReadFrom(r io.Reader) (n int64, err error)

func (*FakeFile) Readdir

func (f *FakeFile) Readdir(n int) ([]os.FileInfo, error)

func (*FakeFile) Readdirnames

func (f *FakeFile) Readdirnames(n int) (names []string, err error)

func (*FakeFile) Seek

func (f *FakeFile) Seek(offset int64, whence int) (ret int64, err error)

func (*FakeFile) Stat

func (f *FakeFile) Stat() (os.FileInfo, error)

func (*FakeFile) Sync

func (f *FakeFile) Sync() error

func (*FakeFile) Truncate

func (f *FakeFile) Truncate(size int64) error

func (*FakeFile) Write

func (f *FakeFile) Write(b []byte) (n int, err error)

func (*FakeFile) WriteAt

func (f *FakeFile) WriteAt(b []byte, off int64) (n int, err error)

func (*FakeFile) WriteString

func (f *FakeFile) WriteString(s string) (n int, err error)

type File

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

func NewFromOs

func NewFromOs(fp *os.File) *File

func (*File) Chdir

func (f *File) Chdir() error

func (*File) Chmod

func (f *File) Chmod(mode os.FileMode) error

func (*File) Chown

func (f *File) Chown(uid, gid int) error

func (*File) Close

func (f *File) Close() error

func (*File) Fd

func (f *File) Fd() uintptr

func (*File) IsFake

func (f *File) IsFake() bool

func (*File) Name

func (f *File) Name() string

func (*File) Read

func (f *File) Read(b []byte) (n int, err error)

func (*File) ReadAt

func (f *File) ReadAt(b []byte, off int64) (n int, err error)

func (*File) ReadDir

func (f *File) ReadDir(n int) ([]os.DirEntry, error)

func (*File) ReadFrom

func (f *File) ReadFrom(r io.Reader) (n int64, err error)

func (*File) Readdir

func (f *File) Readdir(n int) ([]os.FileInfo, error)

func (*File) Readdirnames

func (f *File) Readdirnames(n int) (names []string, err error)

func (*File) Seek

func (f *File) Seek(offset int64, whence int) (ret int64, err error)

func (*File) SetDeadline

func (f *File) SetDeadline(t time.Time) error

func (*File) SetReadDeadline

func (f *File) SetReadDeadline(t time.Time) error

func (*File) SetWriteDeadline

func (f *File) SetWriteDeadline(t time.Time) error

func (*File) Stat

func (f *File) Stat() (os.FileInfo, error)

func (*File) Sync

func (f *File) Sync() error

func (*File) Truncate

func (f *File) Truncate(size int64) error

func (*File) Write

func (f *File) Write(b []byte) (n int, err error)

func (*File) WriteAt

func (f *File) WriteAt(b []byte, off int64) (n int, err error)

func (*File) WriteString

func (f *File) WriteString(s string) (n int, err error)

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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