fakeobj

package
v0.6.15 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package fakeobj provides a fake object for testing. such as fake fs.File, fs.FileInfo, fs.DirEntry etc.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DirEntry

type DirEntry struct {
	Dir bool
	Nam string // basename
	Mod fs.FileMode
	Fi  fs.FileInfo
	Err error
}

DirEntry implements the fs.DirEntry

func NewDirEntry

func NewDirEntry(fpath string, isDir ...bool) *DirEntry

NewDirEntry create a fs.DirEntry

func (*DirEntry) Info

func (d *DirEntry) Info() (fs.FileInfo, error)

Info get

func (*DirEntry) IsDir

func (d *DirEntry) IsDir() bool

IsDir get

func (*DirEntry) Name

func (d *DirEntry) Name() string

Name get

func (*DirEntry) Type

func (d *DirEntry) Type() fs.FileMode

Type get

type FileInfo

type FileInfo struct {
	Dir bool
	Nam string // basename
	Mod fs.FileMode
	Mt  time.Time

	// Path full path
	Path string

	Contents string
	CloseErr error
	// contains filtered or unexported fields
}

FileInfo implements the fs.FileInfo, fs.File

func NewFile

func NewFile(fpath string) *FileInfo

NewFile instance

func NewFileInfo

func NewFileInfo(fpath string, isDir ...bool) *FileInfo

NewFileInfo instance

func (*FileInfo) Close

func (f *FileInfo) Close() error

Close closes the file

func (*FileInfo) IsDir

func (f *FileInfo) IsDir() bool

IsDir returns true if the file is a directory.

func (*FileInfo) ModTime

func (f *FileInfo) ModTime() time.Time

ModTime returns the modification time.

func (*FileInfo) Mode

func (f *FileInfo) Mode() fs.FileMode

Mode returns file mode bits.

func (*FileInfo) Name

func (f *FileInfo) Name() string

Name returns the base name of the file.

func (*FileInfo) Read

func (f *FileInfo) Read(p []byte) (int, error)

Read reads up to len(p) bytes into p.

func (*FileInfo) Reset

func (f *FileInfo) Reset() *FileInfo

Reset prepares a FileInfo for reuse.

func (*FileInfo) Size

func (f *FileInfo) Size() int64

Size returns the length in bytes for regular files; system-dependent for others.

func (*FileInfo) Stat

func (f *FileInfo) Stat() (fs.FileInfo, error)

Stat returns the FileInfo structure describing file.

func (*FileInfo) Sys

func (f *FileInfo) Sys() any

Sys returns underlying data source (can return nil).

func (*FileInfo) WithBody

func (f *FileInfo) WithBody(s string) *FileInfo

WithBody set file body contents

func (*FileInfo) WithMtime

func (f *FileInfo) WithMtime(mt time.Time) *FileInfo

WithMtime set file modify time

type IOWriter added in v0.6.12

type IOWriter struct {
	Buf []byte
	// ErrOnWrite return error on write, useful for testing
	ErrOnWrite bool
}

IOWriter only implements the io.Writer

func NewIOWriter added in v0.6.12

func NewIOWriter() *IOWriter

NewIOWriter instance

func (*IOWriter) Reset added in v0.6.12

func (w *IOWriter) Reset()

Reset the buffer

func (*IOWriter) Write added in v0.6.12

func (w *IOWriter) Write(p []byte) (n int, err error)

Write implements

type Reader added in v0.6.12

type Reader struct {
	byteutil.Buffer
	// ErrOnRead return error on read, useful for testing
	ErrOnRead bool
}

Reader implements the io.Reader, io.Closer

func NewReader added in v0.6.12

func NewReader() *Reader

NewReader instance

func NewStrReader added in v0.6.13

func NewStrReader(s string) *Reader

NewStrReader instance

func (*Reader) Read added in v0.6.12

func (r *Reader) Read(p []byte) (n int, err error)

Read implements the io.Reader

func (*Reader) SetErrOnRead added in v0.6.12

func (r *Reader) SetErrOnRead()

SetErrOnRead mark

type Writer

type Writer struct {
	byteutil.Buffer
	// ErrOnWrite return error on write, useful for testing
	ErrOnWrite bool
	// ErrOnFlush return error on flush, useful for testing
	ErrOnFlush bool
	// ErrOnSync return error on flush, useful for testing
	ErrOnSync bool
	// ErrOnClose return error on close, useful for testing
	ErrOnClose bool
}

Writer implements the io.Writer, stdio.Flusher, io.Closer.

func NewBuffer

func NewBuffer() *Writer

NewBuffer instance. alias of NewWriter()

func NewWriter

func NewWriter() *Writer

NewWriter instance

func (*Writer) Close

func (w *Writer) Close() error

Close implements

func (*Writer) Flush

func (w *Writer) Flush() error

Flush implements stdio.Flusher

func (*Writer) ResetGet

func (w *Writer) ResetGet() string

ResetGet buffer string.

func (*Writer) SetErrOnClose

func (w *Writer) SetErrOnClose() *Writer

SetErrOnClose method

func (*Writer) SetErrOnFlush

func (w *Writer) SetErrOnFlush() *Writer

SetErrOnFlush method

func (*Writer) SetErrOnSync added in v0.6.11

func (w *Writer) SetErrOnSync() *Writer

SetErrOnSync method

func (*Writer) SetErrOnWrite

func (w *Writer) SetErrOnWrite() *Writer

SetErrOnWrite method

func (*Writer) Sync added in v0.6.11

func (w *Writer) Sync() error

Sync implements stdio.Syncer

func (*Writer) Write

func (w *Writer) Write(p []byte) (n int, err error)

Write implements

Jump to

Keyboard shortcuts

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