channeldb: inject clock into database

Use our standard clock mock for database time queries.
This commit is contained in:
Joost Jager committed 2020-01-20 11:08:30 +01:00
1 parent ad0a89b844
commit b600ecda86
7 files changed
+29 -15

No files matched your search

+5 -4
View File
@@ -110,7 +110,7 @@ var (
}
)
func newTestChannelDB() (*channeldb.DB, func(), error) {
func newTestChannelDB(clock clock.Clock) (*channeldb.DB, func(), error) {
// First, create a temporary directory to be used for the duration of
// this test.
tempDirName, err := ioutil.TempDir("", "channeldb")
@@ -119,7 +119,9 @@ func newTestChannelDB() (*channeldb.DB, func(), error) {
}
// Next, create channeldb for the first time.
cdb, err := channeldb.Open(tempDirName)
cdb, err := channeldb.Open(
tempDirName, channeldb.OptionClock(clock),
)
if err != nil {
os.RemoveAll(tempDirName)
return nil, nil, err
@@ -145,11 +147,10 @@ type testContext struct {
func newTestContext(t *testing.T) *testContext {
clock := clock.NewTestClock(testTime)
cdb, cleanup, err := newTestChannelDB()
cdb, cleanup, err := newTestChannelDB(clock)
if err != nil {
t.Fatal(err)
}
cdb.Now = clock.Now
expiryWatcher := NewInvoiceExpiryWatcher(clock)