clockmock

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package clockmock provides moq-generated mock implementations of the clock package's interfaces. For most tests no double is needed at all — a testing/synctest bubble runs the production clock on fake time; reach for these mocks when a test needs to assert on the exact calls a unit makes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClockMock

type ClockMock struct {
	// NewTickerFunc mocks the NewTicker method.
	NewTickerFunc func(d time.Duration) clock.Ticker

	// NowFunc mocks the Now method.
	NowFunc func() time.Time

	// SinceFunc mocks the Since method.
	SinceFunc func(t time.Time) time.Duration

	// SleepFunc mocks the Sleep method.
	SleepFunc func(ctx context.Context, d time.Duration) error
	// contains filtered or unexported fields
}

ClockMock is a mock implementation of clock.Clock.

func TestSomethingThatUsesClock(t *testing.T) {

	// make and configure a mocked clock.Clock
	mockedClock := &ClockMock{
		NewTickerFunc: func(d time.Duration) clock.Ticker {
			panic("mock out the NewTicker method")
		},
		NowFunc: func() time.Time {
			panic("mock out the Now method")
		},
		SinceFunc: func(t time.Time) time.Duration {
			panic("mock out the Since method")
		},
		SleepFunc: func(ctx context.Context, d time.Duration) error {
			panic("mock out the Sleep method")
		},
	}

	// use mockedClock in code that requires clock.Clock
	// and then make assertions.

}

func (*ClockMock) NewTicker

func (mock *ClockMock) NewTicker(d time.Duration) clock.Ticker

NewTicker calls NewTickerFunc.

func (*ClockMock) NewTickerCalls

func (mock *ClockMock) NewTickerCalls() []struct {
	D time.Duration
}

NewTickerCalls gets all the calls that were made to NewTicker. Check the length with:

len(mockedClock.NewTickerCalls())

func (*ClockMock) Now

func (mock *ClockMock) Now() time.Time

Now calls NowFunc.

func (*ClockMock) NowCalls

func (mock *ClockMock) NowCalls() []struct {
}

NowCalls gets all the calls that were made to Now. Check the length with:

len(mockedClock.NowCalls())

func (*ClockMock) Since

func (mock *ClockMock) Since(t time.Time) time.Duration

Since calls SinceFunc.

func (*ClockMock) SinceCalls

func (mock *ClockMock) SinceCalls() []struct {
	T time.Time
}

SinceCalls gets all the calls that were made to Since. Check the length with:

len(mockedClock.SinceCalls())

func (*ClockMock) Sleep

func (mock *ClockMock) Sleep(ctx context.Context, d time.Duration) error

Sleep calls SleepFunc.

func (*ClockMock) SleepCalls

func (mock *ClockMock) SleepCalls() []struct {
	Ctx context.Context
	D   time.Duration
}

SleepCalls gets all the calls that were made to Sleep. Check the length with:

len(mockedClock.SleepCalls())

type TickerMock

type TickerMock struct {
	// ChanFunc mocks the Chan method.
	ChanFunc func() <-chan time.Time

	// StopFunc mocks the Stop method.
	StopFunc func()
	// contains filtered or unexported fields
}

TickerMock is a mock implementation of clock.Ticker.

func TestSomethingThatUsesTicker(t *testing.T) {

	// make and configure a mocked clock.Ticker
	mockedTicker := &TickerMock{
		ChanFunc: func() <-chan time.Time {
			panic("mock out the Chan method")
		},
		StopFunc: func()  {
			panic("mock out the Stop method")
		},
	}

	// use mockedTicker in code that requires clock.Ticker
	// and then make assertions.

}

func (*TickerMock) Chan

func (mock *TickerMock) Chan() <-chan time.Time

Chan calls ChanFunc.

func (*TickerMock) ChanCalls

func (mock *TickerMock) ChanCalls() []struct {
}

ChanCalls gets all the calls that were made to Chan. Check the length with:

len(mockedTicker.ChanCalls())

func (*TickerMock) Stop

func (mock *TickerMock) Stop()

Stop calls StopFunc.

func (*TickerMock) StopCalls

func (mock *TickerMock) StopCalls() []struct {
}

StopCalls gets all the calls that were made to Stop. Check the length with:

len(mockedTicker.StopCalls())

Jump to

Keyboard shortcuts

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