testutil

package
v0.0.555 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: Apache-2.0 Imports: 20 Imported by: 11

Documentation

Index

Constants

View Source
const (
	TEST                 = "TEST"
	TestEmail            = "test@fabriktor.com"
	TestPhone            = "+14508474524"
	TestUsername         = "Bobino_94"
	TestFirstName        = "Bobino"
	TestLastName         = "Bazinet"
	TestVerificationCode = "183423"
	TestUID              = "1234567_OMEWOIFIWMWFTOYONIAGEM890"
	TestProfane          = "dick"
	TestTag              = "tag"
	TestItemName         = "item"
	TestPriceUSD         = 1255
	TestDescription      = "this is a description"
	TestQuantifier       = "box"
)
View Source
const (
	MsgSent       = "[SENT 🌎]"
	MsgReceived   = "[RECEIVED 📮]"
	MsgInsertOne  = "[INSERT ONE]"
	MsgUpsertOne  = "[UPSERT ONE]"
	MsgFindMany   = "[FIND MANY]"
	MsgFindOne    = "[FIND ONE]"
	MsgReplaceOne = "[REPLACE ONE]"
	MsgActions    = "[ACTIONS]"
	MsgDeleteOne  = "[DELETE ONE]"
)
View Source
const (
	TokenTypeFirebase = "firebase"
	TokenTypeOIDC     = "oidc"
)

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

func Body(ctx context.Context, t *testing.T, v any, m contract.Marshaler) io.Reader

Body returns a reader for the given value.

func ClearExtracted

func ClearExtracted()

func Extract

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

Extract finds a field in the response body and appends its value to opts.To.

func FailOnError

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

FailOnError fails the test if the error is not nil.

func GetExtracted

func GetExtracted() string

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 MultipartBody

func MultipartBody(ctx context.Context, opts MultipartBodyOptions) (io.Reader, string)

MultipartBody returns a multipart reader built from file paths in the test filesystem and a content type.

func MustExtracted

func MustExtracted(t *testing.T) string

func Run

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

func WSClose added in v0.0.533

func WSClose(opts WSRequestOptions, ws *WSConn) error

WSClose closes a websocket connection.

func WSReadLoop added in v0.0.533

func WSReadLoop(opts WSRequestOptions, ws *WSConn)

WSReadLoop reads websocket messages until close or error and triggers callbacks.

func WSWrite added in v0.0.533

WSWrite writes a websocket bytes message.

func WSWriteClose added in v0.0.533

func WSWriteClose(opts WSRequestOptions, ws *WSConn) error

WSWriteClose writes a websocket close message, optionally with code.

Types

type Config

type Config struct {
	Ctx            context.Context
	BaseURL        string
	T              *toolbox.Toolbox
	Extract        map[string]string
	Field          string
	Token          TokenSet
	K              Keys
	BeforeTestCase TestCaseHookFunc
	BeforeEach     HookFunc
	AfterEach      HookFunc
	AfterTestCase  TestCaseHookFunc
	SleepBetween   time.Duration
	WS             []*WSConn
}

func (*Config) AssertWSMessages added in v0.0.540

func (cfg *Config) AssertWSMessages(t *testing.T, tc *TestCase) []*contract.WebSocketBytesMessage

AssertWSMessages waits for and validates the expected websocket messages.

func (*Config) CloseAllWS added in v0.0.534

func (cfg *Config) CloseAllWS()

CloseAllWS closes all pooled websocket connections.

func (*Config) GetAuthHeader

func (cfg *Config) GetAuthHeader(prefix, tokenType string) string

func (*Config) NewWS added in v0.0.534

func (cfg *Config) NewWS(opts WSRequestOptions) *WSConn

NewWS creates a websocket connection from options and stores it in the config pool.

func (*Config) Put

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

func (*Config) SetHeaderKeyUserID

func (cfg *Config) SetHeaderKeyUserID(x string)

func (*Config) SetOIDCToken

func (cfg *Config) SetOIDCToken(x string)

func (*Config) SetToken

func (cfg *Config) SetToken(x string)

func (*Config) WaitForWSMessages added in v0.0.540

func (cfg *Config) WaitForWSMessages(n int, timeout time.Duration) ([]*contract.WebSocketBytesMessage, error)

WaitForWSMessages waits until it collects n messages across ALL ws conns, or until timeout.

type ExtractionOption

type ExtractionOption[T comparable] = contract.Opt[ExtractionOptions[T]]

func WithBypass

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

func WithExtractionBody

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

func WithField

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

func WithMarshaler

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

func WithReader

func WithReader[T comparable](x contract.Reader) ExtractionOption[T]

func WithT

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

func WithTo

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

func WithUnmarshaler

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
	R      contract.Reader
	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

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

type HookFunc

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

type Keys

type Keys struct {
	HeaderKeyUserID string
}

type LogDependencies

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

type LogOption

type LogOption = contract.Opt[LogOptions]

func WithLoggedCollection

func WithLoggedCollection(x string) LogOption

func WithLoggedDescription

func WithLoggedDescription(x string) LogOption

func WithLoggedMethod

func WithLoggedMethod(x string) LogOption

func WithLoggedMsg

func WithLoggedMsg(x string) LogOption

func WithLoggedTitle

func WithLoggedTitle(x string) LogOption

func WithLoggedURL

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 MultipartBodyOptions

type MultipartBodyOptions struct {
	T     *testing.T
	FS    fs.ReadFileFS
	FSO   contract.FSysOperator
	M     contract.MultipartOperator
	Paths []string
}

type Request

type Request struct {
	Opts RequestOptions
}

func NewRequest

func NewRequest(opts RequestOptions) *Request

type RequestOption

type RequestOption = contract.Opt[RequestOptions]

func WithBody

func WithBody(x io.Reader) RequestOption

func WithBodyFunc

func WithBodyFunc(x func() io.Reader) RequestOption

func WithExecutions

func WithExecutions(x uint) RequestOption

func WithExpected

func WithExpected(x ...int) RequestOption

func WithExtractField

func WithExtractField() RequestOption

func WithHeader

func WithHeader(x http.Header) RequestOption

func WithHeaderAdd

func WithHeaderAdd(k, v string) RequestOption

func WithHeaderSet

func WithHeaderSet(k, v string) RequestOption

func WithMethod

func WithMethod(x string) RequestOption

func WithMsg

func WithMsg(x string) RequestOption

func WithMultipartBody

func WithMultipartBody(x io.Reader, ct string) RequestOption

func WithPath

func WithPath(x ...string) RequestOption

func WithQuery

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

func WithTimeout

func WithTimeout(x time.Duration) RequestOption

func WithTitle

func WithTitle(x string) RequestOption

func WithUseExtracted

func WithUseExtracted() RequestOption

type RequestOptions

type RequestOptions struct {
	Method       string
	Title        string
	Msg          string
	Path         []string
	Query        map[string][]string
	Expected     []int
	Body         io.Reader
	BodyFunc     func() io.Reader
	Executions   uint
	Header       http.Header
	ExtractField bool
	UseExtracted bool
	Timeout      time.Duration
}

func ApplyRequestOptions

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

type TestCase

type TestCase struct {
	Collection string
	R          []*Request
	WSExpect   int
	WSTimeout  time.Duration
}

type TestCaseHookFunc added in v0.0.537

type TestCaseHookFunc func(*Config, *TestCase)

type TokenSet

type TokenSet struct {
	Firebase string
	OIDC     string
}

type WSConn added in v0.0.533

type WSConn struct {
	C        *contract.WebSocketConn
	Received chan *contract.WebSocketBytesMessage
	Name     string
}

func RunWSRequest added in v0.0.533

func RunWSRequest(opts WSRequestOptions) *WSConn

RunWSRequest builds a websocket URL from request options and dials it.

type WSRequestOption added in v0.0.533

type WSRequestOption = contract.Opt[WSRequestOptions]

func WithWSBaseURL added in v0.0.533

func WithWSBaseURL(x string) WSRequestOption

func WithWSCloseCode added in v0.0.533

func WithWSCloseCode(x *int) WSRequestOption

func WithWSCloseDelay added in v0.0.533

func WithWSCloseDelay(x time.Duration) WSRequestOption

func WithWSCloseMsg added in v0.0.533

func WithWSCloseMsg(x string) WSRequestOption

func WithWSCollection added in v0.0.533

func WithWSCollection(x string) WSRequestOption

func WithWSCtx added in v0.0.533

func WithWSCtx(x context.Context) WSRequestOption

func WithWSGreeting added in v0.0.533

func WithWSGreeting(x []byte) WSRequestOption

func WithWSHeader added in v0.0.533

func WithWSHeader(x http.Header) WSRequestOption

func WithWSInstantClose added in v0.0.533

func WithWSInstantClose(x bool) WSRequestOption

func WithWSOnClose added in v0.0.533

func WithWSOnClose(x func()) WSRequestOption

func WithWSOnMessage added in v0.0.533

func WithWSOnMessage(x func(*contract.WebSocketBytesMessage)) WSRequestOption

func WithWSPath added in v0.0.533

func WithWSPath(x ...string) WSRequestOption

func WithWSQuery added in v0.0.533

func WithWSQuery(k string, v ...string) WSRequestOption

func WithWSReadLoop added in v0.0.533

func WithWSReadLoop(x bool) WSRequestOption

func WithWSTesting added in v0.0.533

func WithWSTesting(x *testing.T) WSRequestOption

func WithWSToolbox added in v0.0.533

type WSRequestOptions added in v0.0.533

type WSRequestOptions struct {
	Ctx           context.Context
	T             *testing.T
	BaseURL       string
	Collection    string
	Path          []string
	Query         map[string][]string
	Header        http.Header
	Toolbox       contract.WebSocketOperator
	OnMessage     func(*contract.WebSocketBytesMessage)
	OnClose       func()
	ReadLoop      bool
	WriteGreeting []byte
	CloseDelay    time.Duration
	CloseCode     *int
	CloseMsg      string
	InstantClose  bool
}

func ApplyWSRequestOptions added in v0.0.533

func ApplyWSRequestOptions(opts *WSRequestOptions, modifiers ...WSRequestOption) WSRequestOptions

Jump to

Keyboard shortcuts

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