mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 18:10:34 +01:00
7024f36a76
This commit adds Clock and DefaultClock and moves the private invoices.testClock under the clock package while adding basic unit tests for it. Clock is an interface currently encapsulating Now() and TickAfter(). It can be added as an external dependency to any class. This way tests can stub out time.Now() or time.After(). The DefaultClock class simply returns the real time.Now() and time.After().
25 lines
505 B
Go
25 lines
505 B
Go
package clock
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
// DefaultClock implements Clock interface by simply calling the appropriate
|
|
// time functions.
|
|
type DefaultClock struct{}
|
|
|
|
// NewDefaultClock constructs a new DefaultClock.
|
|
func NewDefaultClock() Clock {
|
|
return &DefaultClock{}
|
|
}
|
|
|
|
// Now simply returns time.Now().
|
|
func (DefaultClock) Now() time.Time {
|
|
return time.Now()
|
|
}
|
|
|
|
// TickAfter simply wraps time.After().
|
|
func (DefaultClock) TickAfter(duration time.Duration) <-chan time.Time {
|
|
return time.After(duration)
|
|
}
|