Skip to content

v3: refactor request/response mocking to use a unified MockDoer API #487

@bigbes

Description

@bigbes

Currently, the test mocks for the Tarantool client use separate types for
mocking requests and responses (e.g., a standalone ResponseMock). This
makes test setup verbose and exposes internal implementation details that
users shouldn’t need to manage.

We want to simplify and unify the mocking interface by introducing a single,
fluent MockDoer that lets tests declaratively define expected responses
while automatically capturing incoming requests.

Proposed API

Replace the current approach with a MockDoer interface like this:

type MockDoer interface {
    // Add a successful response with just payload data
    AddResponseOk1(data []interface{}) MockDoer

    // Add a successful response with explicit header and body
    AddResponseOk2(header tarantool.Header, body io.Reader) MockDoer

    // Add an error response (e.g., network or protocol error)
    AddResponseError(err error) MockDoer

    // Return all requests that were sent to this mock during the test
    Requests() []tarantool.Request
}

This design:

  • Uses method chaining for easy setup
  • Hides low-level response construction (e.g., no need to build full Response structs manually)

Example Usage

mockDoer := mock.NewDoer().
    AddResponseOk1([]interface{}{"OK"}).
    AddResponseError(io.EOF)

client := tarantool.NewClient(mockDoer)
_, err := client.Call("some.func", nil) // succeeds
_, err = client.Call("another.func", nil) // returns io.EOF

// Later in test:
assert.Len(t, mockDoer.Requests(), 2)
assert.Equal(t, "some.func", mockDoer.Requests()[0].(tarantool.CallRequest).FunctionName)

Related links and repos

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions