fakeobj

package
v0.6.10 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2023 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

	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

func (*FileInfo) IsDir

func (f *FileInfo) IsDir() bool

func (*FileInfo) ModTime

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

func (*FileInfo) Mode

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

func (*FileInfo) Name

func (f *FileInfo) Name() string

func (*FileInfo) Read

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

func (*FileInfo) Reset

func (f *FileInfo) Reset() *FileInfo

Reset prepares a FileInfo for reuse.

func (*FileInfo) Size

func (f *FileInfo) Size() int64

func (*FileInfo) Stat

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

func (*FileInfo) Sys

func (f *FileInfo) Sys() any

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 Writer

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

Writer implements the io.Writer, io.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

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) SetErrOnWrite

func (w *Writer) SetErrOnWrite() *Writer

SetErrOnWrite method

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