Documentation ¶
Overview ¶
Package testhelpers contains various test helper functions
Index ¶
- func ClosingRecorder(t *testing.T) *httptest.ResponseRecorder
- func RandomString(prefix string, length int) string
- type MockDBExecutor
- func (m *MockDBExecutor) BindNamed(s string, i any) (string, []any, error)
- func (*MockDBExecutor) DriverName() string
- func (m *MockDBExecutor) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
- func (m *MockDBExecutor) GetContext(ctx context.Context, dest any, query string, args ...any) error
- func (m *MockDBExecutor) NamedExecContext(ctx context.Context, query string, arg any) (sql.Result, error)
- func (m *MockDBExecutor) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
- func (m *MockDBExecutor) QueryRowxContext(ctx context.Context, query string, args ...any) *sqlx.Row
- func (m *MockDBExecutor) QueryxContext(ctx context.Context, query string, args ...any) (*sqlx.Rows, error)
- func (m *MockDBExecutor) Rebind(s string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClosingRecorder ¶
func ClosingRecorder(t *testing.T) *httptest.ResponseRecorder
ClosingRecorder creates new httptest.ResponseRecorder and closing body at cleanup.
func RandomString ¶
RandomString generates random string with given prefix.
Types ¶
type MockDBExecutor ¶
MockDBExecutor sqlx.DB replacement for testing.
func (*MockDBExecutor) DriverName ¶
func (*MockDBExecutor) DriverName() string
DriverName returns "mock".
func (*MockDBExecutor) ExecContext ¶
func (m *MockDBExecutor) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
ExecContext returns affectedRowsResult and expectedError.
func (*MockDBExecutor) GetContext ¶
GetContext mocks sqlx.DB GetContext method, loading m.expectedDest to dest.
func (*MockDBExecutor) NamedExecContext ¶
func (m *MockDBExecutor) NamedExecContext(ctx context.Context, query string, arg any) (sql.Result, error)
NamedExecContext returns m.affectedRowsResult, m.expectedError.
func (*MockDBExecutor) QueryContext ¶
func (m *MockDBExecutor) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
QueryContext returns expectedRows and expectedError.
func (*MockDBExecutor) QueryRowxContext ¶
QueryRowxContext returns expectedRow.
func (*MockDBExecutor) QueryxContext ¶
func (m *MockDBExecutor) QueryxContext(ctx context.Context, query string, args ...any) (*sqlx.Rows, error)
QueryxContext returns expectedRows and expectedError.
func (*MockDBExecutor) Rebind ¶
func (m *MockDBExecutor) Rebind(s string) string
Rebind calls to sqlx.Rebind with UNKNOWN bindType.