mocks

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientStreamClientMock

type ClientStreamClientMock[Req any, Res any] struct {
	// contains filtered or unexported fields
}

func NewClientStreamClientMock

func NewClientStreamClientMock[Req any, Res any](
	response *Res,
	sendErrors []error,
) *ClientStreamClientMock[Req, Res]

func (*ClientStreamClientMock[Req, Res]) CloseAndRecv

func (c *ClientStreamClientMock[Req, Res]) CloseAndRecv() (*Res, error)

func (*ClientStreamClientMock[Req, Res]) CloseSend

func (c *ClientStreamClientMock[Req, Res]) CloseSend() error

func (*ClientStreamClientMock[Req, Res]) Context

func (c *ClientStreamClientMock[Req, Res]) Context() context.Context

func (*ClientStreamClientMock[Req, Res]) Header

func (c *ClientStreamClientMock[Req, Res]) Header() (metadata.MD, error)

func (*ClientStreamClientMock[Req, Res]) RecvMsg

func (c *ClientStreamClientMock[Req, Res]) RecvMsg(m any) error

func (*ClientStreamClientMock[Req, Res]) Requests

func (c *ClientStreamClientMock[Req, Res]) Requests() []*Req

func (*ClientStreamClientMock[Req, Res]) Send

func (c *ClientStreamClientMock[Req, Res]) Send(req *Req) error

func (*ClientStreamClientMock[Req, Res]) SendMsg

func (c *ClientStreamClientMock[Req, Res]) SendMsg(m any) error

func (*ClientStreamClientMock[Req, Res]) Trailer

func (c *ClientStreamClientMock[Req, Res]) Trailer() metadata.MD

type KVStorageClientMock

type KVStorageClientMock struct {
	// DeleteFunc mocks the Delete method.
	DeleteFunc func(ctx context.Context, in *bytestream.ReadRequest, opts ...grpc.CallOption) (*kv_storage.DeleteResponse, error)

	// GetFunc mocks the Get method.
	GetFunc func(ctx context.Context, in *bytestream.ReadRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[bytestream.ReadResponse], error)

	// PutFunc mocks the Put method.
	PutFunc func(ctx context.Context, opts ...grpc.CallOption) (grpc.ClientStreamingClient[bytestream.WriteRequest, bytestream.WriteResponse], error)
	// contains filtered or unexported fields
}

KVStorageClientMock is a mock implementation of kv_storage.KVStorageClient.

func TestSomethingThatUsesKVStorageClient(t *testing.T) {

	// make and configure a mocked kv_storage.KVStorageClient
	mockedKVStorageClient := &KVStorageClientMock{
		DeleteFunc: func(ctx context.Context, in *bytestream.ReadRequest, opts ...grpc.CallOption) (*kv_storage.DeleteResponse, error) {
			panic("mock out the Delete method")
		},
		GetFunc: func(ctx context.Context, in *bytestream.ReadRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[bytestream.ReadResponse], error) {
			panic("mock out the Get method")
		},
		PutFunc: func(ctx context.Context, opts ...grpc.CallOption) (grpc.ClientStreamingClient[bytestream.WriteRequest, bytestream.WriteResponse], error) {
			panic("mock out the Put method")
		},
	}

	// use mockedKVStorageClient in code that requires kv_storage.KVStorageClient
	// and then make assertions.

}

func (*KVStorageClientMock) Delete

Delete calls DeleteFunc.

func (*KVStorageClientMock) DeleteCalls

func (mock *KVStorageClientMock) DeleteCalls() []struct {
	Ctx  context.Context
	In   *bytestream.ReadRequest
	Opts []grpc.CallOption
}

DeleteCalls gets all the calls that were made to Delete. Check the length with:

len(mockedKVStorageClient.DeleteCalls())

func (*KVStorageClientMock) Get

Get calls GetFunc.

func (*KVStorageClientMock) GetCalls

func (mock *KVStorageClientMock) GetCalls() []struct {
	Ctx  context.Context
	In   *bytestream.ReadRequest
	Opts []grpc.CallOption
}

GetCalls gets all the calls that were made to Get. Check the length with:

len(mockedKVStorageClient.GetCalls())

func (*KVStorageClientMock) Put

Put calls PutFunc.

func (*KVStorageClientMock) PutCalls

func (mock *KVStorageClientMock) PutCalls() []struct {
	Ctx  context.Context
	Opts []grpc.CallOption
}

PutCalls gets all the calls that were made to Put. Check the length with:

len(mockedKVStorageClient.PutCalls())

type RecvResult

type RecvResult[Res any] struct {
	Response *Res
	Error    error
	Metadata map[string]string
}

type ServerStreamingClientMock

type ServerStreamingClientMock[Res any] struct {
	// contains filtered or unexported fields
}

func NewServerStreamingClientMock

func NewServerStreamingClientMock[Res any](recvResults []RecvResult[Res]) *ServerStreamingClientMock[Res]

func (*ServerStreamingClientMock[Res]) CloseSend

func (s *ServerStreamingClientMock[Res]) CloseSend() error

func (*ServerStreamingClientMock[Res]) Context

func (s *ServerStreamingClientMock[Res]) Context() context.Context

func (*ServerStreamingClientMock[Res]) Header

func (s *ServerStreamingClientMock[Res]) Header() (metadata.MD, error)

func (*ServerStreamingClientMock[Res]) Recv

func (s *ServerStreamingClientMock[Res]) Recv() (*Res, error)

func (*ServerStreamingClientMock[Res]) RecvMsg

func (s *ServerStreamingClientMock[Res]) RecvMsg(m any) error

func (*ServerStreamingClientMock[Res]) SendMsg

func (s *ServerStreamingClientMock[Res]) SendMsg(m any) error

func (*ServerStreamingClientMock[Res]) Trailer

func (s *ServerStreamingClientMock[Res]) Trailer() metadata.MD

Jump to

Keyboard shortcuts

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