Documentation
¶
Index ¶
- Constants
- func Assert(t *testing.T, r *http.Response, expected []int)
- func Body(ctx context.Context, t *testing.T, v any, m contract.Marshaler) io.Reader
- func ClearExtracted()
- func Extract[T comparable](ctx context.Context, opts ExtractionOptions[T])
- func FailOnError(t *testing.T, err error)
- func GetExtracted() string
- func Log(ctx context.Context, t *testing.T, d LogDependencies, opts LogOptions) error
- func MultipartBody(ctx context.Context, opts MultipartBodyOptions) (io.Reader, string)
- func MustExtracted(t *testing.T) string
- func Run(t *testing.T, cfg *Config, tcases []*TestCase)
- func WSClose(opts WSRequestOptions, ws *WSConn) error
- func WSReadLoop(opts WSRequestOptions, ws *WSConn)
- func WSWrite(opts WSRequestOptions, ws *WSConn, t contract.WebSocketMessageType, b []byte) error
- func WSWriteClose(opts WSRequestOptions, ws *WSConn) error
- type Config
- func (cfg *Config) AssertWSMessages(t *testing.T, tc *TestCase) []*contract.WebSocketBytesMessage
- func (cfg *Config) CloseAllWS()
- func (cfg *Config) GetAuthHeader(prefix, tokenType string) string
- func (cfg *Config) NewWS(opts WSRequestOptions) *WSConn
- func (cfg *Config) Put(k, v string)
- func (cfg *Config) SetHeaderKeyUserID(x string)
- func (cfg *Config) SetOIDCToken(x string)
- func (cfg *Config) SetToken(x string)
- func (cfg *Config) WaitForWSMessages(n int, timeout time.Duration) ([]*contract.WebSocketBytesMessage, error)
- type ExtractionOption
- func WithBypass[T comparable](x bool) ExtractionOption[T]
- func WithExtractionBody[T comparable](x io.Reader) ExtractionOption[T]
- func WithField[T comparable](x string) ExtractionOption[T]
- func WithMarshaler[T comparable](x contract.Marshaler) ExtractionOption[T]
- func WithReader[T comparable](x contract.Reader) ExtractionOption[T]
- func WithT[T comparable](x *testing.T) ExtractionOption[T]
- func WithTo[T comparable](x *[]T) ExtractionOption[T]
- func WithUnmarshaler[T comparable](x contract.Unmarshaler) ExtractionOption[T]
- type ExtractionOptions
- type HookFunc
- type Keys
- type LogDependencies
- type LogOption
- type LogOptions
- type MultipartBodyOptions
- type Request
- type RequestOption
- func WithBody(x io.Reader) RequestOption
- func WithBodyFunc(x func() io.Reader) RequestOption
- func WithExecutions(x uint) RequestOption
- func WithExpected(x ...int) RequestOption
- func WithExtractField() RequestOption
- func WithHeader(x http.Header) RequestOption
- func WithHeaderAdd(k, v string) RequestOption
- func WithHeaderSet(k, v string) RequestOption
- func WithMethod(x string) RequestOption
- func WithMsg(x string) RequestOption
- func WithMultipartBody(x io.Reader, ct string) RequestOption
- func WithPath(x ...string) RequestOption
- func WithQuery(k string, v ...string) RequestOption
- func WithTimeout(x time.Duration) RequestOption
- func WithTitle(x string) RequestOption
- func WithUseExtracted() RequestOption
- type RequestOptions
- type TestCase
- type TestCaseHookFunc
- type TokenSet
- type WSConn
- type WSRequestOption
- func WithWSBaseURL(x string) WSRequestOption
- func WithWSCloseCode(x *int) WSRequestOption
- func WithWSCloseDelay(x time.Duration) WSRequestOption
- func WithWSCloseMsg(x string) WSRequestOption
- func WithWSCollection(x string) WSRequestOption
- func WithWSCtx(x context.Context) WSRequestOption
- func WithWSGreeting(x []byte) WSRequestOption
- func WithWSHeader(x http.Header) WSRequestOption
- func WithWSInstantClose(x bool) WSRequestOption
- func WithWSOnClose(x func()) WSRequestOption
- func WithWSOnMessage(x func(*contract.WebSocketBytesMessage)) WSRequestOption
- func WithWSPath(x ...string) WSRequestOption
- func WithWSQuery(k string, v ...string) WSRequestOption
- func WithWSReadLoop(x bool) WSRequestOption
- func WithWSTesting(x *testing.T) WSRequestOption
- func WithWSToolbox(x contract.WebSocketOperator) WSRequestOption
- type WSRequestOptions
Constants ¶
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" )
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]" )
const ( TokenTypeFirebase = "firebase" TokenTypeOIDC = "oidc" )
Variables ¶
This section is empty.
Functions ¶
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 ¶
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 ¶
MultipartBody returns a multipart reader built from file paths in the test filesystem and a content type.
func MustExtracted ¶
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
func WSWrite(opts WSRequestOptions, ws *WSConn, t contract.WebSocketMessageType, b []byte) error
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
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 (*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) SetHeaderKeyUserID ¶
func (*Config) SetOIDCToken ¶
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 LogDependencies ¶
type LogOption ¶
type LogOption = contract.Opt[LogOptions]
func WithLoggedCollection ¶
func WithLoggedDescription ¶
func WithLoggedMethod ¶
func WithLoggedMsg ¶
func WithLoggedTitle ¶
func WithLoggedURL ¶
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 TestCaseHookFunc ¶ added in v0.0.537
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
func WithWSToolbox(x contract.WebSocketOperator) WSRequestOption
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