fake

package
v0.20.2 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFakeWriter = errors.New("naza.fake: a fake writer error")
)

Functions

func Os_Exit

func Os_Exit(code int)

正常情况下,调用 os.Exit,单元测试时,可通过调用 WithFakeExit 配置为不调用 os.Exit

func Time_Now

func Time_Now() time.Time

func WithFakeTimeNow

func WithFakeTimeNow(n func() time.Time, fn func())

func WithRecover

func WithRecover(f func())

Types

type ExitResult

type ExitResult struct {
	HasExit  bool
	ExitCode int
}

func WithFakeOsExit

func WithFakeOsExit(fn func()) ExitResult

type Writer

type Writer struct {
	B bytes.Buffer
	// contains filtered or unexported fields
}

func NewWriter

func NewWriter(t WriterType) *Writer

func (*Writer) SetSpecificType

func (w *Writer) SetSpecificType(ts map[uint32]WriterType)

为某些写操作指定特定的类型,次数从 0 开始计数

func (*Writer) Write

func (w *Writer) Write(b []byte) (int, error)

type WriterType

type WriterType uint8
const (
	WriterTypeDoNothing WriterType = iota
	WriterTypeReturnError
	WriterTypeIntoBuffer
)

Jump to

Keyboard shortcuts

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