testhelpers

package
v0.0.0-...-1f1cd5d Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package testhelpers contains various test helper functions

Index

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

func RandomString(prefix string, length int) string

RandomString generates random string with given prefix.

Types

type MockDBExecutor

type MockDBExecutor struct {
	mock.Mock
}

MockDBExecutor sqlx.DB replacement for testing.

func (*MockDBExecutor) BindNamed

func (m *MockDBExecutor) BindNamed(s string, i any) (string, []any, error)

BindNamed calls to sqx.Named.

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

func (m *MockDBExecutor) GetContext(ctx context.Context, dest any, query string, args ...any) error

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

func (m *MockDBExecutor) QueryRowxContext(ctx context.Context, query string, args ...any) *sqlx.Row

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.

Jump to

Keyboard shortcuts

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