generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: module unit tests can allow calls within module (#1373)
We already have a way of providing verb mocks/fakes with `ftltest.WhenVerb(...)` but sometimes with tests it can be useful to allow calls to work fine within the module. This PR enables this behaviour though it has to be explicitly enabled by the test. This allows the person writing the test to better understand what their unit test is touching. --- Below is a rundown of how ftltest works for a test writer in practice: _⌨️ Write module `echo` which has verb `Echo` and `InnerEcho`. `Echo` calls `InnerEcho`, `InnerEcho` calls `time.Time`_ _⌨️ Write the following test:_ ``` func TestEcho(t *testing.T) { ctx := ftltest.Context( ftltest.WithConfig(defaultName, "fallback"), ) resp, err := Echo(ctx, EchoRequest{Name: ftl.Some("world")}) assert.NoError(t, err) assert.Equal(t, "Hello, world!!! It is 2024-01-01 00:00:00 +0000 UTC!", resp.Message) } ``` 🤖 Error: > echo.innerEcho: no mock found: provide a mock with ftltest.WhenVerb(innerEcho, ...) or enable all calls within the module with ftltest.WithCallsAllowedWithinModule() _⌨️ Add `ftltest.WithCallsAllowedWithinModule()` to `ftltest.Context()` options_ 🤖 Error: > echo.innerEcho: time.time: no mock found: provide a mock with ftltest.WhenVerb(time.time, ...) _⌨️ Add the following to `ftltest.Context()` options_: ``` ftltest.WhenVerb(time.Time, func(ctx context.Context, req time.TimeRequest) (time.TimeResponse, error) { return time.TimeResponse{Time: stdtime.Date(2024, 1, 1, 0, 0, 0, 0, stdtime.UTC)}, nil }) ``` 🤖 success
- Loading branch information
Showing
15 changed files
with
377 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module = "wrapped" | ||
language = "go" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module ftl/wrapped | ||
|
||
go 1.22.2 | ||
|
||
require ( | ||
github.com/TBD54566975/ftl v0.193.0 | ||
github.com/alecthomas/assert/v2 v2.9.0 | ||
) | ||
|
||
require ( | ||
connectrpc.com/connect v1.14.0 // indirect | ||
connectrpc.com/grpcreflect v1.2.0 // indirect | ||
connectrpc.com/otelconnect v0.7.0 // indirect | ||
github.com/BurntSushi/toml v1.3.2 // indirect | ||
github.com/TBD54566975/scaffolder v0.8.0 // indirect | ||
github.com/alecthomas/concurrency v0.0.2 // indirect | ||
github.com/alecthomas/kong v0.9.0 // indirect | ||
github.com/alecthomas/participle/v2 v2.1.1 // indirect | ||
github.com/alecthomas/repr v0.4.0 // indirect | ||
github.com/alecthomas/types v0.14.0 // indirect | ||
github.com/alessio/shellescape v1.4.2 // indirect | ||
github.com/danieljoos/wincred v1.2.0 // indirect | ||
github.com/go-logr/logr v1.4.1 // indirect | ||
github.com/go-logr/stdr v1.2.2 // indirect | ||
github.com/godbus/dbus/v5 v5.1.0 // indirect | ||
github.com/hexops/gotextdiff v1.0.3 // indirect | ||
github.com/jackc/pgpassfile v1.0.0 // indirect | ||
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect | ||
github.com/jackc/pgx/v5 v5.5.5 // indirect | ||
github.com/jackc/puddle/v2 v2.2.1 // indirect | ||
github.com/jpillora/backoff v1.0.0 // indirect | ||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect | ||
github.com/mattn/go-isatty v0.0.20 // indirect | ||
github.com/multiformats/go-base36 v0.2.0 // indirect | ||
github.com/swaggest/jsonschema-go v0.3.70 // indirect | ||
github.com/swaggest/refl v1.3.0 // indirect | ||
github.com/zalando/go-keyring v0.2.4 // indirect | ||
go.opentelemetry.io/otel v1.26.0 // indirect | ||
go.opentelemetry.io/otel/metric v1.26.0 // indirect | ||
go.opentelemetry.io/otel/trace v1.26.0 // indirect | ||
golang.org/x/crypto v0.22.0 // indirect | ||
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect | ||
golang.org/x/mod v0.17.0 // indirect | ||
golang.org/x/net v0.24.0 // indirect | ||
golang.org/x/sync v0.7.0 // indirect | ||
golang.org/x/sys v0.19.0 // indirect | ||
golang.org/x/text v0.14.0 // indirect | ||
google.golang.org/protobuf v1.33.0 // indirect | ||
) | ||
|
||
replace github.com/TBD54566975/ftl => ../../../.. |
Oops, something went wrong.