ftltest

package
v0.213.0 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package ftltest contains test utilities for the ftl package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Context

func Context(options ...Option) context.Context

Context suitable for use in testing FTL verbs with provided options

Types

type Option added in v0.201.0

type Option func(context.Context, *OptionsState) error

func WhenEmpty added in v0.202.3

func WhenEmpty(empty ftl.Empty, fake func(ctx context.Context) (err error)) Option

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.Empty, func(ctx context.Context) error {
    ...
}),
... other options

)

func WhenSink added in v0.202.3

func WhenSink[Req any](sink ftl.Sink[Req], fake func(ctx context.Context, req Req) error) Option

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.Sink, func(ctx context.Context, req Example.Req) error {
    ...
}),
... other options

)

func WhenSource added in v0.202.3

func WhenSource[Resp any](source ftl.Source[Resp], fake func(ctx context.Context) (resp Resp, err error)) Option

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.Source, func(ctx context.Context) (Example.Resp, error) {
    ...
}),
... other options

)

func WhenVerb added in v0.189.0

func WhenVerb[Req any, Resp any](verb ftl.Verb[Req, Resp], fake ftl.Verb[Req, Resp]) Option

WhenVerb replaces an implementation for a verb

To be used when setting up a context for a test: ctx := ftltest.Context(

ftltest.WhenVerb(Example.Verb, 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

func WithDatabase(dbHandle ftl.Database) Option

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 WithProjectFiles added in v0.202.6

func WithProjectFiles(paths ...string) Option

WithProjectFiles loads config and secrets from a project file

Takes a list of paths to project files. If multiple paths are provided, they are loaded in order, with later files taking precedence. If no paths are provided, the list is inferred from the FTL_CONFIG environment variable. If that is not found, an error is returned.

To be used when setting up a context for a test: ctx := ftltest.Context(

ftltest.WithProjectFiles("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

)

type OptionsState added in v0.201.0

type OptionsState struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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