testutil

package
v0.0.518 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

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)

Types

type Config

type Config struct {
	Ctx           context.Context
	BaseURL       string
	T             *toolbox.Toolbox
	Extract       map[string]string
	Field         string
	Token         TokenSet
	K             Keys
	BeforeEach    HookFunc
	AfterEach     HookFunc
	AfterTestCase func(Config, *TestCase)
	SleepBetween  time.Duration
}

func (*Config) GetAuthHeader

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

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)

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
}

type TokenSet

type TokenSet struct {
	Firebase string
	OIDC     string
}

Jump to

Keyboard shortcuts

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