testing

package
v0.0.0-...-c36b4a8 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2025 License: BSD-2-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package testing provides a mock implementation of the tarantool.Doer and other interfaces. It is used for testing purposes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DummyT

type DummyT struct {
	testing.T
	// contains filtered or unexported fields
}

DummyT is a dummy implementation of the testing.T interface to use in examples.

func NewT

func NewT() *DummyT

NewT returns a new dummy T instance.

func (*DummyT) Attr

func (t *DummyT) Attr(_, _ string)

Attr is a dummy implementation of the testing.T interface to use in examples.

func (*DummyT) Chdir

func (t *DummyT) Chdir(_ string)

Chdir is a dummy implementation of the testing.T interface to use in examples.

func (*DummyT) Cleanup

func (t *DummyT) Cleanup(f func())

Cleanup is a dummy implementation of the testing.T interface to use in examples.

func (*DummyT) Cleanups

func (t *DummyT) Cleanups()

Cleanups should be called to call all cleanup functions on "test" exit.

func (*DummyT) Error

func (t *DummyT) Error(_ ...any)

Error is a dummy implementation of the testing.T interface to use in examples.

func (*DummyT) Errorf

func (t *DummyT) Errorf(format string, args ...any)

Errorf is a dummy implementation of the testing.T interface to use in examples.

func (*DummyT) Fail

func (t *DummyT) Fail()

Fail is a dummy implementation of the testing.T interface to use in examples.

func (*DummyT) FailNow

func (t *DummyT) FailNow()

FailNow is a dummy implementation of the testing.T interface to use in examples.

func (*DummyT) Failed

func (t *DummyT) Failed() bool

Failed is a dummy implementation of the testing.T interface to use in examples.

func (*DummyT) Fatal

func (t *DummyT) Fatal(args ...any)

Fatal is a dummy implementation of the testing.T interface to use in examples.

func (*DummyT) Fatalf

func (t *DummyT) Fatalf(format string, args ...any)

Fatalf is a dummy implementation of the testing.T interface to use in examples.

func (*DummyT) Helper

func (t *DummyT) Helper()

Helper is a dummy implementation of the testing.T interface to use in examples.

func (*DummyT) Log

func (t *DummyT) Log(args ...any)

Log is a dummy implementation of the testing.T interface to use in examples.

func (*DummyT) Logf

func (t *DummyT) Logf(format string, args ...any)

Logf is a dummy implementation of the testing.T interface to use in examples.

func (*DummyT) Name

func (t *DummyT) Name() string

Name is a dummy implementation of the testing.T interface to use in examples.

func (*DummyT) Setenv

func (t *DummyT) Setenv(_, _ string)

Setenv is a dummy implementation of the testing.T interface to use in examples.

func (*DummyT) Skip

func (t *DummyT) Skip(_ ...any)

Skip is a dummy implementation of the testing.T interface to use in examples.

func (*DummyT) SkipNow

func (t *DummyT) SkipNow()

SkipNow is a dummy implementation of the testing.T interface to use in examples.

func (*DummyT) Skipf

func (t *DummyT) Skipf(format string, args ...any)

Skipf is a dummy implementation of the testing.T interface to use in examples.

func (*DummyT) Skipped

func (t *DummyT) Skipped() bool

Skipped is a dummy implementation of the testing.T interface to use in examples.

type MockDoer

type MockDoer struct {

	// Requests is a slice of received requests.
	// It could be used to compare incoming requests with expected.
	Requests []tarantool.Request
	// contains filtered or unexported fields
}

MockDoer is an implementation of the Doer interface used for testing purposes.

func NewMockDoer

func NewMockDoer(t T, responses ...any) *MockDoer

NewMockDoer creates a MockDoer by given responses. Each response could be one of two types: MockResponse or error.

func (*MockDoer) Do

func (d *MockDoer) Do(req tarantool.Request) *tarantool.Future

Do returns a future with the current response or an error. It saves the current request into MockDoer.Requests.

type MockDoerWithWatcher

type MockDoerWithWatcher struct {
	// contains filtered or unexported fields
}

MockDoerWithWatcher is a mock implementation of the tarantool.DoerWithWatcher interface.

func NewMockDoerWithWatcher

func NewMockDoerWithWatcher(doer *MockDoer, events map[string][]tarantool.WatchEvent) *MockDoerWithWatcher

NewMockDoerWithWatcher returns a new mock doer with watcher.

func (*MockDoerWithWatcher) Do

func (m *MockDoerWithWatcher) Do(req tarantool.Request) *tarantool.Future

Do returns a new future.

func (*MockDoerWithWatcher) NewWatcher

func (m *MockDoerWithWatcher) NewWatcher(path string, callback tarantool.WatchCallback) (tarantool.Watcher, error)

NewWatcher returns a new watcher.

type MockRequest

type MockRequest struct {
}

MockRequest is an empty mock request used for testing purposes.

func NewMockRequest

func NewMockRequest() *MockRequest

NewMockRequest creates an empty MockRequest.

func (*MockRequest) Async

func (req *MockRequest) Async() bool

Async returns if MockRequest expects a response.

func (*MockRequest) Body

func (req *MockRequest) Body(_ tarantool.SchemaResolver, _ *msgpack.Encoder) error

Body fills an msgpack.Encoder with the watch request body.

func (*MockRequest) Conn

func (req *MockRequest) Conn() *tarantool.Connection

Conn returns the Connection object the request belongs to.

func (*MockRequest) Ctx

func (req *MockRequest) Ctx() context.Context

Ctx returns a context of the MockRequest.

func (*MockRequest) Response

func (req *MockRequest) Response(
	header tarantool.Header, body io.Reader,
) (tarantool.Response, error)

Response creates a response for the MockRequest.

func (*MockRequest) Type

func (req *MockRequest) Type() iproto.Type

Type returns an iproto type for MockRequest.

type MockResponse

type MockResponse struct {
	// contains filtered or unexported fields
}

MockResponse is a mock response used for testing purposes.

func CreateMockResponse

func CreateMockResponse(header tarantool.Header, body io.Reader) (*MockResponse, error)

CreateMockResponse creates a MockResponse from the header and a data, packed inside an io.Reader.

func NewMockResponse

func NewMockResponse(t T, body any) *MockResponse

NewMockResponse creates a new MockResponse with an empty header and the given data. body should be passed as a structure to be encoded. The encoded body is served as response data and will be decoded once the response is decoded.

func (*MockResponse) Decode

func (resp *MockResponse) Decode() ([]any, error)

Decode returns the result of decoding the response data as slice.

func (*MockResponse) DecodeTyped

func (resp *MockResponse) DecodeTyped(res any) error

DecodeTyped returns the result of decoding the response data.

func (*MockResponse) Header

func (resp *MockResponse) Header() tarantool.Header

Header returns a header for the MockResponse.

type T

type T interface {
	Helper()
	Log(args ...any)
	Logf(format string, args ...any)
	Fatalf(format string, args ...any)
	Errorf(format string, args ...any)
}

T is a dummy implementation of the testing.T interface to use in examples.

Jump to

Keyboard shortcuts

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