general: adding the Clock interface to aid testing

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().
This commit is contained in:
Andras Banki-Horvath
2019-11-25 11:46:29 +01:00
parent ff3063daea
commit 7024f36a76
8 changed files with 131 additions and 31 deletions

16
clock/interface.go Normal file
View File

@@ -0,0 +1,16 @@
package clock
import (
"time"
)
// Clock is an interface that provides a time functions for LND packages.
// This is useful during testing when a concrete time reference is needed.
type Clock interface {
// Now returns the current local time (as defined by the Clock).
Now() time.Time
// TickAfter returns a channel that will receive a tick after the specified
// duration has passed.
TickAfter(duration time.Duration) <-chan time.Time
}