Documentation ¶
Overview ¶
Package ftltest contains test utilities for the ftl package.
Index ¶
- func Call[VerbClient, Req, Resp any](ctx context.Context, req Req) (Resp, error)
- func CallEmpty[VerbClient any](ctx context.Context) error
- func CallSink[VerbClient, Req any](ctx context.Context, req Req) error
- func CallSource[VerbClient, Resp any](ctx context.Context) (Resp, error)
- func Context(options ...Option) context.Context
- func ErrorsForSubscription[E any](ctx context.Context, subscription ftl.SubscriptionHandle[E]) []error
- func EventsForTopic[E any](ctx context.Context, topic ftl.TopicHandle[E]) []E
- func SubContext(ctx context.Context, options ...Option) context.Context
- func WaitForSubscriptionsToComplete(ctx context.Context)
- type Option
- func WhenEmpty[EmptyClient any](fake ftl.Empty) Option
- func WhenMap[T, U any](mapper *ftl.MapHandle[T, U], fake func(context.Context) (U, error)) Option
- func WhenSink[SinkClient, Req any](fake ftl.Sink[Req]) Option
- func WhenSource[SourceClient, Resp any](fake ftl.Source[Resp]) Option
- func WhenVerb[VerbClient, Req, Resp any](fake ftl.Verb[Req, Resp]) Option
- func WithCallsAllowedWithinModule() Option
- func WithConfig[T ftl.ConfigType](config ftl.ConfigValue[T], value T) Option
- func WithDatabase(dbHandle ftl.Database) Option
- func WithDefaultProjectFile() Option
- func WithMapsAllowed() Option
- func WithProjectFile(path string) Option
- func WithSecret[T ftl.SecretType](secret ftl.SecretValue[T], value T) Option
- func WithSubscriber[E any](subscription ftl.SubscriptionHandle[E], sink ftl.Sink[E]) Option
- type OptionsState
- type SubscriptionResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CallEmpty ¶ added in v0.374.0
CallEmpty calls an Empty inline, applying resources and test behavior.
func CallSink ¶ added in v0.374.0
CallSink calls a Sink inline, applying resources and test behavior.
func CallSource ¶ added in v0.374.0
CallSource calls a Source inline, applying resources and test behavior.
func ErrorsForSubscription ¶ added in v0.254.0
func ErrorsForSubscription[E any](ctx context.Context, subscription ftl.SubscriptionHandle[E]) []error
ErrorsForSubscription returns all errors encountered while consuming events for a subscription
func EventsForTopic ¶ added in v0.254.0
func EventsForTopic[E any](ctx context.Context, topic ftl.TopicHandle[E]) []E
EventsForTopic returns all published events for a topic
func SubContext ¶ added in v0.360.0
SubContext applies the given options to the given context, creating a new context extending the previous one.
Does not modify the existing context
func WaitForSubscriptionsToComplete ¶ added in v0.254.0
WaitForSubscriptionsToComplete waits until all subscriptions have consumed all events
Subscriptions with no manually activated subscribers are ignored. Make sure you have called WithSubscriber(…) for all subscriptions you want to wait for.
Types ¶
type Option ¶ added in v0.201.0
type Option struct {
// contains filtered or unexported fields
}
func WhenEmpty ¶ added in v0.202.3
WhenEmpty replaces an implementation for a verb with no request or response
To be used when setting up a context for a test:
ctx := ftltest.Context( ftltest.WhenEmpty[example.EmptyClient](func(ctx context.Context) error { ... }), )
func WhenMap ¶ added in v0.243.0
WhenMap injects a fake implementation of a Mapping function
To be used when setting up a context for a test:
ctx := ftltest.Context( ftltest.WhenMap(Example.MapHandle, func(ctx context.Context) (U, error) { // ... }), // ... other options )
func WhenSink ¶ added in v0.202.3
WhenSink replaces an implementation for a verb with no response
To be used when setting up a context for a test:
ctx := ftltest.Context( ftltest.WhenSink[example.SinkClient](func(ctx context.Context, req example.Req) error { ... }), // ... other options )
func WhenSource ¶ added in v0.202.3
WhenSource replaces an implementation for a verb with no request
To be used when setting up a context for a test:
ctx := ftltest.Context( ftltest.WhenSource[example.SourceClient](func(ctx context.Context) (example.Resp, error) { // ... }), // ... other options )
func WhenVerb ¶ added in v0.189.0
WhenVerb replaces an implementation for a verb
To be used when setting up a context for a test:
ctx := ftltest.Context( ftltest.WhenVerb[example.VerbClient](func(ctx context.Context, req example.Req) (example.Resp, error) { // ... }), // ... other options )
func WithCallsAllowedWithinModule ¶ added in v0.196.0
func WithCallsAllowedWithinModule() Option
WithCallsAllowedWithinModule allows tests to enable calls to all verbs within the current module
Any overrides provided by calling WhenVerb(...) will take precedence
func WithConfig ¶ added in v0.189.0
func WithConfig[T ftl.ConfigType](config ftl.ConfigValue[T], value T) Option
WithConfig sets a configuration for the current module
To be used when setting up a context for a test:
ctx := ftltest.Context( ftltest.WithConfig(exampleEndpoint, "https://example.com"), // ... other options )
func WithDatabase ¶ added in v0.207.0
WithDatabase sets up a database for testing by appending "_test" to the DSN and emptying all tables
To be used when setting up a context for a test:
ctx := ftltest.Context( ftltest.WithDatabase(db), // ... other options )
func WithDefaultProjectFile ¶ added in v0.255.0
func WithDefaultProjectFile() Option
WithDefaultProjectFile loads config and secrets from the default project file, which is either the FTL_CONFIG environment variable or the ftl-project.toml file in the git root.
func WithMapsAllowed ¶ added in v0.243.0
func WithMapsAllowed() Option
WithMapsAllowed allows all `ftl.Map` calls to pass through to their original implementation.
Any overrides provided by calling WhenMap(...) will take precedence.
func WithProjectFile ¶ added in v0.201.0
WithProjectFile loads config and secrets from a project file
Takes a path to an FTL project file. If an empty path is provided, the path is inferred from the FTL_CONFIG environment variable. If that is not found, the ftl-project.toml file in the git root is used. If a project file is not found, an error is returned.
To be used when setting up a context for a test:
ctx := ftltest.Context( ftltest.WithProjectFile("path/to/ftl-project.yaml"), // ... other options )
func WithSecret ¶ added in v0.189.0
func WithSecret[T ftl.SecretType](secret ftl.SecretValue[T], value T) Option
WithSecret sets a secret for the current module
To be used when setting up a context for a test:
ctx := ftltest.Context( ftltest.WithSecret(privateKey, "abc123"), // ... other options )
func WithSubscriber ¶ added in v0.254.0
WithSubscriber adds a subscriber during a test
By default, all subscribers are disabled in unit tests, and must be manually enabled by calling WithSubscriber(…). This allows easy isolation for each unit test.
WithSubscriber(…) can also be used to make an ad-hoc subscriber for your test by defining a new function as the sink.
To be used when setting up a context for a test:
ctx := ftltest.Context( ftltest.WithSubscriber(paymentTopic, ProcessPayment), // ... other options )
type OptionsState ¶ added in v0.201.0
type OptionsState struct {
// contains filtered or unexported fields
}
type SubscriptionResult ¶ added in v0.254.0
func ResultsForSubscription ¶ added in v0.254.0
func ResultsForSubscription[E any](ctx context.Context, subscription ftl.SubscriptionHandle[E]) []SubscriptionResult[E]
ResultsForSubscription returns all consumed events for a subscription, with any resulting errors