mock

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

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

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) Key

func (mock *LockMock) Key() string

Key calls KeyFunc.

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) Refresh

func (mock *LockMock) Refresh(ctx context.Context, ttl time.Duration) error

Refresh calls RefreshFunc.

func (*LockMock) RefreshCalls

func (mock *LockMock) RefreshCalls() []struct {
	Ctx context.Context
	TTL time.Duration
}

RefreshCalls gets all the calls that were made to Refresh. Check the length with:

len(mockedLock.RefreshCalls())

func (*LockMock) Release

func (mock *LockMock) Release(ctx context.Context) error

Release calls ReleaseFunc.

func (*LockMock) ReleaseCalls

func (mock *LockMock) ReleaseCalls() []struct {
	Ctx context.Context
}

ReleaseCalls gets all the calls that were made to Release. Check the length with:

len(mockedLock.ReleaseCalls())

func (*LockMock) TTL

func (mock *LockMock) TTL() time.Duration

TTL calls TTLFunc.

func (*LockMock) TTLCalls

func (mock *LockMock) TTLCalls() []struct {
}

TTLCalls gets all the calls that were made to TTL. Check the length with:

len(mockedLock.TTLCalls())

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) Close

func (mock *LockerMock) Close() error

Close calls CloseFunc.

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())

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL