lnmock: add new package lnmock to host mocks
This commit introduces a new package to host mocked objects that can be used for all the unit tests.
This commit is contained in:
2 files changed
+37
No files matched your search
@@ -238,3 +238,10 @@ issues:
|
|||||||
- govet
|
- govet
|
||||||
# itest case can be very long so we disable long function check.
|
# itest case can be very long so we disable long function check.
|
||||||
- funlen
|
- funlen
|
||||||
|
|
||||||
|
- path: lnmock/*
|
||||||
|
linters:
|
||||||
|
# forcetypeassert is skipped for the mock because the test would fail
|
||||||
|
# if the returned value doesn't match the type, so there's no need to
|
||||||
|
# check the convert.
|
||||||
|
- forcetypeassert
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
// NOTE: forcetypeassert is skipped for the mock because the test would fail if
|
||||||
|
// the returned value doesn't match the type.
|
||||||
|
package lnmock
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/lightningnetwork/lnd/clock"
|
||||||
|
"github.com/stretchr/testify/mock"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MockClock implements the `clock.Clock` interface.
|
||||||
|
type MockClock struct {
|
||||||
|
mock.Mock
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compile time assertion that MockClock implements clock.Clock.
|
||||||
|
var _ clock.Clock = (*MockClock)(nil)
|
||||||
|
|
||||||
|
func (m *MockClock) Now() time.Time {
|
||||||
|
args := m.Called()
|
||||||
|
|
||||||
|
return args.Get(0).(time.Time)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MockClock) TickAfter(d time.Duration) <-chan time.Time {
|
||||||
|
args := m.Called(d)
|
||||||
|
|
||||||
|
return args.Get(0).(chan time.Time)
|
||||||
|
}
|
||||||
Reference in new issue
Block a user