testutil

package
v0.1.225 Latest Latest
Warning

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

Go to latest
Published: May 12, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MsgSent       = "| Sent 🌎     |"
	MsgReceived   = "| Received 📮 |"
	MsgInsertOne  = "Insert One"
	MsgFindMany   = "Find Many"
	MsgFindOne    = "Find One"
	MsgReplaceOne = "Replace One"
	MsgActions    = "Actions"
	MsgDeleteOne  = "Delete One"
)

Variables

This section is empty.

Functions

func Assert

func Assert(t *testing.T, r *http.Response, expected []int)

Assert verifies that the response status is within the accepted statuses.

func Body added in v0.1.218

func Body(t *testing.T, v any, m contract.Marshaler) *bytes.Reader

Body returns a reader for the given value.

func Extract

func Extract[T comparable](t *testing.T, body io.Reader, u contract.Unmarshaler, field string, to *[]T, opts ExtractionOptions)

Extract extracts a field from the response body.

func FailOnError

func FailOnError(t *testing.T, err error)

FailOnError fails the test if the error is not nil.

func Log

func Log(ctx context.Context, t *testing.T, logger contract.LogOperator, body io.Reader, opts LogOptions) error

Log creates a detailed log entry for integration tests requests and responses.

func Run added in v0.1.223

func Run(t *testing.T, cfg Config, tcases []*TestCase)

Types

type Config added in v0.1.223

type Config struct {
	Ctx        context.Context
	BaseURL    string
	T          *toolbox.Toolbox
	Extract    map[string]string
	Token      string
	BeforeEach HookFunc
	AfterEach  HookFunc
}

type ExtractionOption

type ExtractionOption func(*ExtractionOptions)

func WithBypass

func WithBypass(bypass bool) ExtractionOption

WithBypass specifies whether to bypass the extraction.

type ExtractionOptions

type ExtractionOptions struct {
	Bypass bool
}

func ApplyExtractionOptions

func ApplyExtractionOptions(opts *ExtractionOptions, modifiers ...ExtractionOption) ExtractionOptions

type HookFunc added in v0.1.223

type HookFunc func(Config, *TestCase, Request)

type LogOption

type LogOption func(*LogOptions)

func WithLoggedCollection added in v0.1.223

func WithLoggedCollection(x string) LogOption

func WithLoggedDescription added in v0.1.223

func WithLoggedDescription(x string) LogOption

func WithLoggedMethod added in v0.1.223

func WithLoggedMethod(x string) LogOption

func WithLoggedMsg added in v0.1.223

func WithLoggedMsg(x string) LogOption

func WithLoggedTitle added in v0.1.223

func WithLoggedTitle(x string) LogOption

func WithLoggedURL added in v0.1.223

func WithLoggedURL(x string) LogOption

type LogOptions

type LogOptions struct {
	Method      string
	URL         string
	Msg         string
	Title       string
	Collection  string
	Description string
}

func ApplyLogOptions

func ApplyLogOptions(opts *LogOptions, modifiers ...LogOption) LogOptions

type Request added in v0.1.223

type Request struct {
	Opts RequestOptions
}

func NewRequest added in v0.1.223

func NewRequest(opts RequestOptions) *Request

type RequestOption added in v0.1.223

type RequestOption func(*RequestOptions)

func WithBody added in v0.1.223

func WithBody(x io.Reader) RequestOption

func WithExecutions added in v0.1.223

func WithExecutions(x uint) RequestOption

func WithExpected

func WithExpected(x ...int) RequestOption

func WithHeader added in v0.1.223

func WithHeader(k, v string) RequestOption

func WithMethod

func WithMethod(x string) RequestOption

func WithMsg added in v0.1.222

func WithMsg(x string) RequestOption

func WithNeedsExtractedID added in v0.1.225

func WithNeedsExtractedID(x bool) RequestOption

func WithPath added in v0.1.223

func WithPath(x ...string) RequestOption

func WithQuery added in v0.1.223

func WithQuery(k string, v ...string) RequestOption

func WithTitle added in v0.1.222

func WithTitle(x string) RequestOption

type RequestOptions added in v0.1.223

type RequestOptions struct {
	Method           string
	Title            string
	Msg              string
	Path             []string
	Query            map[string][]string
	Expected         []int
	Body             io.Reader
	Executions       uint
	Header           http.Header
	NeedsExtractedID bool
}

func ApplyRequestOptions added in v0.1.223

func ApplyRequestOptions(opts *RequestOptions, modifiers ...RequestOption) RequestOptions

type TestCase added in v0.1.223

type TestCase struct {
	Collection string
	R          []*Request
}

Jump to

Keyboard shortcuts

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