Documentation
¶
Overview ¶
Package mock provides mock implementations of the distributedlock package's interfaces. Both the hand-written testify-based Locker/Lock types and the moq-generated LockerMock/LockMock types live here during the testify → moq migration. New test code should prefer the moq-generated types.
Index ¶
- type LockMock
- func (mock *LockMock) Key() string
- func (mock *LockMock) KeyCalls() []struct{}
- func (mock *LockMock) Refresh(ctx context.Context, ttl time.Duration) error
- func (mock *LockMock) RefreshCalls() []struct{ ... }
- func (mock *LockMock) Release(ctx context.Context) error
- func (mock *LockMock) ReleaseCalls() []struct{ ... }
- func (mock *LockMock) TTL() time.Duration
- func (mock *LockMock) TTLCalls() []struct{}
- type LockerMock
- func (mock *LockerMock) Acquire(ctx context.Context, key string, ttl time.Duration) (distributedlock.Lock, error)
- func (mock *LockerMock) AcquireCalls() []struct{ ... }
- func (mock *LockerMock) Close() error
- func (mock *LockerMock) CloseCalls() []struct{}
- func (mock *LockerMock) Ping(ctx context.Context) error
- func (mock *LockerMock) PingCalls() []struct{ ... }
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LockMock ¶
type LockMock struct {
// KeyFunc mocks the Key method.
KeyFunc func() string
// RefreshFunc mocks the Refresh method.
RefreshFunc func(ctx context.Context, ttl time.Duration) error
// ReleaseFunc mocks the Release method.
ReleaseFunc func(ctx context.Context) error
// TTLFunc mocks the TTL method.
TTLFunc func() time.Duration
// contains filtered or unexported fields
}
LockMock is a mock implementation of distributedlock.Lock.
func TestSomethingThatUsesLock(t *testing.T) {
// make and configure a mocked distributedlock.Lock
mockedLock := &LockMock{
KeyFunc: func() string {
panic("mock out the Key method")
},
RefreshFunc: func(ctx context.Context, ttl time.Duration) error {
panic("mock out the Refresh method")
},
ReleaseFunc: func(ctx context.Context) error {
panic("mock out the Release method")
},
TTLFunc: func() time.Duration {
panic("mock out the TTL method")
},
}
// use mockedLock in code that requires distributedlock.Lock
// and then make assertions.
}
func (*LockMock) KeyCalls ¶
func (mock *LockMock) KeyCalls() []struct { }
KeyCalls gets all the calls that were made to Key. Check the length with:
len(mockedLock.KeyCalls())
func (*LockMock) RefreshCalls ¶
RefreshCalls gets all the calls that were made to Refresh. Check the length with:
len(mockedLock.RefreshCalls())
func (*LockMock) ReleaseCalls ¶
ReleaseCalls gets all the calls that were made to Release. Check the length with:
len(mockedLock.ReleaseCalls())
type LockerMock ¶
type LockerMock struct {
// AcquireFunc mocks the Acquire method.
AcquireFunc func(ctx context.Context, key string, ttl time.Duration) (distributedlock.Lock, error)
// CloseFunc mocks the Close method.
CloseFunc func() error
// PingFunc mocks the Ping method.
PingFunc func(ctx context.Context) error
// contains filtered or unexported fields
}
LockerMock is a mock implementation of distributedlock.Locker.
func TestSomethingThatUsesLocker(t *testing.T) {
// make and configure a mocked distributedlock.Locker
mockedLocker := &LockerMock{
AcquireFunc: func(ctx context.Context, key string, ttl time.Duration) (distributedlock.Lock, error) {
panic("mock out the Acquire method")
},
CloseFunc: func() error {
panic("mock out the Close method")
},
PingFunc: func(ctx context.Context) error {
panic("mock out the Ping method")
},
}
// use mockedLocker in code that requires distributedlock.Locker
// and then make assertions.
}
func (*LockerMock) Acquire ¶
func (mock *LockerMock) Acquire(ctx context.Context, key string, ttl time.Duration) (distributedlock.Lock, error)
Acquire calls AcquireFunc.
func (*LockerMock) AcquireCalls ¶
func (mock *LockerMock) AcquireCalls() []struct { Ctx context.Context Key string TTL time.Duration }
AcquireCalls gets all the calls that were made to Acquire. Check the length with:
len(mockedLocker.AcquireCalls())
func (*LockerMock) CloseCalls ¶
func (mock *LockerMock) CloseCalls() []struct { }
CloseCalls gets all the calls that were made to Close. Check the length with:
len(mockedLocker.CloseCalls())
func (*LockerMock) Ping ¶
func (mock *LockerMock) Ping(ctx context.Context) error
Ping calls PingFunc.
func (*LockerMock) PingCalls ¶
func (mock *LockerMock) PingCalls() []struct { Ctx context.Context }
PingCalls gets all the calls that were made to Ping. Check the length with:
len(mockedLocker.PingCalls())