-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: module tests can declare config/secrets/DSNs and add verb mocks #1317
Conversation
8f6de76
to
c10e481
Compare
Doc: https://hackmd.io/@ftl/SyynEK2eC Other PRs - [x] Pre-Req: protobuf changes #1312 - [ ] Possible future change for tests moved here: #1317 Changes: - Module server requests module context, instead of calculating them independently from envars - controller alculates values for module context (config, secrets, DSNs), returns it to module via gRPC - Within a module, `ftl.PostgresDatabase(name string)` now returns a handler, with `Get()` needing to be called to get `*sql.DB` - Module context builder is used to compose a module context. It can take in: - a GetModuleContext response, to read in values received over gRPC - manual entry (useful for testing) (see other PR above) - Added in-memory implementations of `configuration.MutableProvider` and `configuration.Resolver`. This allows us to have a backing store for configs and secrets for `ModuleContext` which shares the same behaviour for (un)marshalling json. - `configuration.Manager` now has raw data versions of `Get()` and `Set()` called `GetData()` and `SetData()` which expose the features without needing unnecessary conversion steps. This helps when moving values between configuration managers directly or over gRPC.
33cb463
to
2c1513b
Compare
a1dbff1
to
7bd914f
Compare
41f30a3
to
30f7b0c
Compare
"context" | ||
) | ||
|
||
type CallOverrider interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't want this to be public to module code, but wasn't sure of a better place to put it...
30f7b0c
to
b338886
Compare
@@ -43,8 +43,8 @@ func (v *Ref) UnmarshalText(text []byte) error { | |||
return nil | |||
} | |||
|
|||
func (v *Ref) String() string { return v.Module + "." + v.Name } | |||
func (v *Ref) ToProto() *schemapb.Ref { | |||
func (v Ref) String() string { return v.Module + "." + v.Name } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is because Ref
not *Ref
is used everywhere but printf wasn't formatting it nicely
go-runtime/ftl/ftltest/mock.go
Outdated
// mockProvider keeps a mapping of verb references to mock functions. | ||
// | ||
// It implements the CallOverrider interface to intercept calls with the mock functions. | ||
type mockProvider struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be worth renaming this to mockVerbProvider in case we want to support mocking of entities other than verbs down the road?
DBTypePostgres = DBType(modulecontext.DBTypePostgres) | ||
) | ||
|
||
// Context suitable for use in testing FTL verbs with provided options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super nitty nit: would you mind adding some example code to this comment so that folks don't need to grep around to learn how to use this? Basically exactly what you put in your PR description:
ctx := ftltest.Context (
ftltest.WithConfig("default", "anonymous"),
ftltest.WithSecret("example", "test123"),
ftltest.WithDSN("db", ftltest.DBTypePostgres, "..."),
ftltest.WithFakeVerb(time.Time, func(ctx context. Context, req time. TimeRequest) (time.TimeResponse, error) {
return time.TimeResponse{Time: stdtime.Date(2021, 9, 1, 0, 0, 0, 0, stdtime.UTC)}, nil
},
)
Definitely don't need to include every single option in the example if you want to keep the comment shorter, either. Thanks :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super useful addition! thanks :D
96accdb
to
e31dd78
Compare
# Conflicts: # go-runtime/modulecontext/modulecontext.go # go-runtime/server/server.go
e31dd78
to
9e05028
Compare
c1bfd0c
to
e7a85b9
Compare
Part of: https://hackmd.io/zNiBPIhVQN2hkeNHg2r8YA
This PR makes it easy to set up the following:
Another improvement is when doing unit tests, a simple error message will be returned when attempting to make a
ftl.Call
when there isn't any rpc client set up. This error will be returned: