ffs

package module
v0.0.0-...-741166b Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: Unlicense Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Time = time.Now

Time tells the "current" time. For testing purposes, you can reassign this variable:

ffs.Time = func() (t time.Time) {
	// always return zero value
	return
}

Functions

This section is empty.

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(uncleanedPath string) (File, error)

func (*FakeFileSystem) OpenFile

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

func (*FakeFileSystem) ReadFile

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

func (*FakeFileSystem) Remove

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

func (*FakeFileSystem) RemoveAll

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

func (*FakeFileSystem) Stat

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

func (*FakeFileSystem) String

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

func (*FakeFileSystem) Truncate

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

func (*FakeFileSystem) WalkDir

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

func (*FakeFileSystem) WriteFile

func (m *FakeFileSystem) WriteFile(uncleanedPath 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