testutil

package
v0.1.333 Latest Latest
Warning

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

Go to latest
Published: May 22, 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(ctx context.Context, t *testing.T, v any, m contract.Marshaler) *bytes.Reader

Body returns a reader for the given value.

func Extract

func Extract[T comparable](ctx context.Context, opts ExtractionOptions[T])

Extract extracts a field value 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, d LogDependencies, 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
	Field         string
	Token         string
	BeforeEach    HookFunc
	AfterEach     HookFunc
	AfterTestCase func(Config, *TestCase)
}

func (*Config) Put added in v0.1.226

func (cfg *Config) Put(k, v string)

func (*Config) SetToken added in v0.1.226

func (cfg *Config) SetToken(t string)

type ExtractionOption

type ExtractionOption[T comparable] func(*ExtractionOptions[T])

func WithBypass

func WithBypass[T comparable](x bool) ExtractionOption[T]

func WithExtractionBody added in v0.1.281

func WithExtractionBody[T comparable](x io.Reader) ExtractionOption[T]

func WithField added in v0.1.281

func WithField[T comparable](x string) ExtractionOption[T]

func WithMarshaler added in v0.1.314

func WithMarshaler[T comparable](x contract.Marshaler) ExtractionOption[T]

func WithT added in v0.1.281

func WithT[T comparable](x *testing.T) ExtractionOption[T]

func WithTo added in v0.1.281

func WithTo[T comparable](x *[]T) ExtractionOption[T]

func WithUnmarshaler added in v0.1.281

func WithUnmarshaler[T comparable](x contract.Unmarshaler) ExtractionOption[T]

type ExtractionOptions

type ExtractionOptions[T comparable] struct {
	T      *testing.T
	Body   io.Reader
	Field  string
	To     *[]T
	U      contract.Unmarshaler
	M      contract.Marshaler
	Bypass bool
}

ExtractionOptions contains all parameters for a structured field extraction.

func ApplyExtractionOptions

func ApplyExtractionOptions[T comparable](opts *ExtractionOptions[T], modifiers ...ExtractionOption[T]) ExtractionOptions[T]

func (*ExtractionOptions[T]) Validate added in v0.1.281

func (o *ExtractionOptions[T]) Validate() error

type HookFunc added in v0.1.223

type HookFunc func(Config, *TestCase, *Request)

type LogDependencies added in v0.1.302

type LogDependencies struct {
	B io.Reader
	H http.Header
	R contract.Reader
	G contract.GzipReader
}

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 WithExtractField added in v0.1.331

func WithExtractField() RequestOption

func WithHeader added in v0.1.223

func WithHeader(x http.Header) RequestOption

func WithHeaderAdd added in v0.1.290

func WithHeaderAdd(k, v string) RequestOption

func WithHeaderSet added in v0.1.290

func WithHeaderSet(k, v string) RequestOption

func WithMethod

func WithMethod(x string) RequestOption

func WithMsg added in v0.1.222

func WithMsg(x string) 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

func WithUseExtracted added in v0.1.331

func WithUseExtracted() 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
	ExtractField bool
	UseExtracted 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