From 12db5c32d20c4926d2086182078e2405bad8b6fa Mon Sep 17 00:00:00 2001 From: Alec Thomas Date: Tue, 28 May 2024 08:57:23 +1000 Subject: [PATCH] docs: fix formatting of some godoc example code (#1579) --- go-runtime/ftl/ftltest/ftltest.go | 87 ++++++++++++++----------------- 1 file changed, 39 insertions(+), 48 deletions(-) diff --git a/go-runtime/ftl/ftltest/ftltest.go b/go-runtime/ftl/ftltest/ftltest.go index 3b3fd94b1e..45269697ea 100644 --- a/go-runtime/ftl/ftltest/ftltest.go +++ b/go-runtime/ftl/ftltest/ftltest.go @@ -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 @@ -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() { @@ -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() { @@ -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) @@ -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) @@ -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) @@ -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) @@ -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)