Skip to content

Commit

Permalink
docs: fix formatting of some godoc example code (#1579)
Browse files Browse the repository at this point in the history
  • Loading branch information
alecthomas authored May 27, 2024
1 parent f7cc313 commit 12db5c3
Showing 1 changed file with 39 additions and 48 deletions.
87 changes: 39 additions & 48 deletions go-runtime/ftl/ftltest/ftltest.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,11 @@ func Context(options ...Option) context.Context {
// file in the git root is used. If ftl-project.toml is not found, no project files are loaded.
//
// To be used when setting up a context for a test:
// ctx := ftltest.Context(
//
// ftltest.WithProjectFiles("path/to/ftl-project.yaml"),
// ... other options
//
// )
// ctx := ftltest.Context(
// ftltest.WithProjectFiles("path/to/ftl-project.yaml"),
// // ... other options
// )
func WithProjectFiles(paths ...string) Option {
// Convert to absolute path immediately in case working directory changes
var preprocessingErr error
Expand Down Expand Up @@ -128,12 +127,11 @@ func WithProjectFiles(paths ...string) 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
//
// )
// ctx := ftltest.Context(
// ftltest.WithConfig(exampleEndpoint, "https://example.com"),
// // ... other options
// )
func WithConfig[T ftl.ConfigType](config ftl.ConfigValue[T], value T) Option {
return func(ctx context.Context, state *OptionsState) error {
if config.Module != reflection.Module() {
Expand All @@ -151,12 +149,11 @@ func WithConfig[T ftl.ConfigType](config ftl.ConfigValue[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
//
// )
// ctx := ftltest.Context(
// ftltest.WithSecret(privateKey, "abc123"),
// // ... other options
// )
func WithSecret[T ftl.SecretType](secret ftl.SecretValue[T], value T) Option {
return func(ctx context.Context, state *OptionsState) error {
if secret.Module != reflection.Module() {
Expand All @@ -174,12 +171,11 @@ func WithSecret[T ftl.SecretType](secret ftl.SecretValue[T], value T) 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
//
// )
// ctx := ftltest.Context(
// ftltest.WithDatabase(db),
// // ... other options
// )
func WithDatabase(dbHandle ftl.Database) Option {
return func(ctx context.Context, state *OptionsState) error {
originalDSN, err := modulecontext.GetDSNFromSecret(reflection.Module(), dbHandle.Name, state.secrets)
Expand Down Expand Up @@ -231,14 +227,13 @@ func WithDatabase(dbHandle ftl.Database) 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
//
// )
// ctx := ftltest.Context(
// ftltest.WhenVerb(Example.Verb, func(ctx context.Context, req Example.Req) (Example.Resp, error) {
// // ...
// }),
// // ... other options
// )
func WhenVerb[Req any, Resp any](verb ftl.Verb[Req, Resp], fake ftl.Verb[Req, Resp]) Option {
return func(ctx context.Context, state *OptionsState) error {
ref := reflection.FuncRef(verb)
Expand All @@ -256,14 +251,13 @@ func WhenVerb[Req any, Resp any](verb ftl.Verb[Req, Resp], fake ftl.Verb[Req, Re
// 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
//
// )
// ctx := ftltest.Context(
// ftltest.WhenSource(example.Source, func(ctx context.Context) (example.Resp, error) {
// // ...
// }),
// // ... other options
// )
func WhenSource[Resp any](source ftl.Source[Resp], fake func(ctx context.Context) (resp Resp, err error)) Option {
return func(ctx context.Context, state *OptionsState) error {
ref := reflection.FuncRef(source)
Expand All @@ -277,14 +271,13 @@ func WhenSource[Resp any](source ftl.Source[Resp], fake func(ctx context.Context
// 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
//
// )
// ctx := ftltest.Context(
// ftltest.WhenSink(example.Sink, func(ctx context.Context, req example.Req) error {
// ...
// }),
// // ... other options
// )
func WhenSink[Req any](sink ftl.Sink[Req], fake func(ctx context.Context, req Req) error) Option {
return func(ctx context.Context, state *OptionsState) error {
ref := reflection.FuncRef(sink)
Expand All @@ -302,14 +295,12 @@ func WhenSink[Req any](sink ftl.Sink[Req], fake func(ctx context.Context, req Re
// 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
//
// )
// ctx := ftltest.Context(
// ftltest.WhenEmpty(Example.Empty, func(ctx context.Context) error {
// ...
// }),
// )
func WhenEmpty(empty ftl.Empty, fake func(ctx context.Context) (err error)) Option {
return func(ctx context.Context, state *OptionsState) error {
ref := reflection.FuncRef(empty)
Expand Down

0 comments on commit 12db5c3

Please sign in to comment.