Documentation
¶
Overview ¶
Package testtime provides a mocked version of time.Timer for use in tests.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TestTimer ¶
type TestTimer struct {
// contains filtered or unexported fields
}
TestTimer is a mocked version of time.Timer for which the passage of time or the direct expiration of the timer is controlled manually.
TestTimer implements timeutil.Timer.
TestTimer also provides methods to introspect whether the timer is active or how many times it has fired.
func AfterFunc ¶
AfterFunc waits for the timer to fire and then calls f in its own goroutine. It returns a Timer that can be used to cancel the call using its Stop method. The returned Timer's C field is not used and will be nil.
AfterFunc returns a TestTimer which simulates the behavior of a timer which was created via time.AfterFunc.
See here for more details: https://pkg.go.dev/time#AfterFunc
func NewTimer ¶
NewTimer creates a new Timer that will send the current time on its channel after the timer fires.
NewTimer returns a TestTimer which simulates the behavior of a timer which was created via time.NewTimer.
See here for more details: https://pkg.go.dev/time#NewTimer
func (*TestTimer) Active ¶
Active returns true if the timer is active, false if the timer has expired or been stopped.
func (*TestTimer) Elapse ¶
Elapse simulates time advancing by the given duration, which potentially causes the timer to fire.
The timer will fire if the total elapsed time since the timer was created or reset is greater than the timer's duration and the timer has not yet fired.
func (*TestTimer) Fire ¶
Fire causes the timer to fire. If the timer was created via NewTimer, then sends the given current time over the C channel.
To avoid accidental misuse, panics if the timer is not active (if it has already fired or been stopped).
func (*TestTimer) Reset ¶
Reset changes the timer to expire after duration d. It returns true if the timer had been active, false if the timer had expired or been stopped.
As the test timer does not actually count down, Reset sets the timer's elapsed time to 0 and set its duration to the given duration. The elapsed time must be advanced manually using Elapse.
This simulates the behavior of Timer.Reset() from the time package. See here fore more details: https://pkg.go.dev/time#Timer.Reset
func (*TestTimer) Stop ¶
Stop prevents the timer from firing. It returns true if the call stops the timer, false if the timer has already expired or been stopped.
This simulates the behavior of Timer.Stop() from the time package. See here for more details: https://pkg.go.dev/time#Timer.Stop