mocking

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FakeClock

type FakeClock struct {
	// Value is the embedded time value. This value is advanced
	// by calling Sleep().
	Value time.Time
}

FakeClock is an IClock which returns the embedded time value instead of the real time.

func (FakeClock) Now

func (c FakeClock) Now() time.Time

func (*FakeClock) Sleep

func (c *FakeClock) Sleep(d time.Duration)

type FakePrinter

type FakePrinter struct {
	Builder strings.Builder
}

FakePrinter prints everything to an internal buffer. The buffer can be obtained by calling String().

func (*FakePrinter) PrintMessagef

func (p *FakePrinter) PrintMessagef(format string, a ...interface{})

func (*FakePrinter) PrintMessageln

func (p *FakePrinter) PrintMessageln(a ...interface{})

func (*FakePrinter) PrintOutputln

func (p *FakePrinter) PrintOutputln(a ...interface{})

func (FakePrinter) String

func (p FakePrinter) String() string

type IClock

type IClock interface {
	Now() time.Time
	Sleep(d time.Duration)
}

IClock is a swappable clock interface so that during testing the time can be mocked.

type IPrinter

type IPrinter interface {
	PrintMessageln(a ...interface{})
	PrintMessagef(format string, a ...interface{})
	PrintOutputln(a ...interface{})
}

IPrinter provides a swappable output/message printing interface so that during testing output/messages can be captured.

type RealClock

type RealClock struct{}

RealClock is an IClock which returns the real time.

func (RealClock) Now

func (_ RealClock) Now() time.Time

func (RealClock) Sleep

func (_ RealClock) Sleep(d time.Duration)

type RealPrinter

type RealPrinter struct{}

RealPrinter prints everything to stdout.

func (RealPrinter) PrintMessagef

func (_ RealPrinter) PrintMessagef(format string, a ...interface{})

func (RealPrinter) PrintMessageln

func (_ RealPrinter) PrintMessageln(a ...interface{})

func (RealPrinter) PrintOutputln

func (_ RealPrinter) PrintOutputln(a ...interface{})

Jump to

Keyboard shortcuts

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