You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
it would be cool if i could override what ftl.Map returns when writing tests so that no network calls are required and so non-happy paths can be tested.
For now, i think i'll have to set/unset the global variable in each test.
Some design notes
We have a new system for differentiation between "real" code and "test" code should take place, the FTL interface. We should implement this in there somehow, and add options for ftltest.Context() to set it up and tear it down at the end of the test.
It should probably follow the pattern of how the fakes for verbs are done:
By default all Map calls under testing will panic
An option to allow all Map calls to pass through
A final option to mock individual calls.
These three will give full control.
We'll need to do something like:
Add a FTL.CallMap(ctx context.Context, mapper any) (any, error) method to the FTL interface
Add mockMaps to ftltest.OptionsState
Extend newFakeFTL() to take in the mockMaps
Add options for ftltest.Context() to achieve the above
Replace the ftl.Map.Get implementation with one that uses the FTL interface
I think the API would be something like:
// WhenMap injects a fake implementation of a Mapping functionfuncWhenMap[T, Uany](mapper*ftl.MapHandle[T], fakefunc(context.Context, T) (U, error)) Option// WithMapsAllowed allows all `ftl.Map` calls to pass through to their original implementation, rather thanfuncWithMapsAllowed() Option
The text was updated successfully, but these errors were encountered:
I'm trying to test a verb that makes a request to a third party API whose client is returned using
ftl.Map
e.g.it would be cool if i could override what
ftl.Map
returns when writing tests so that no network calls are required and so non-happy paths can be tested.For now, i think i'll have to set/unset the global variable in each test.
Some design notes
We have a new system for differentiation between "real" code and "test" code should take place, the FTL interface. We should implement this in there somehow, and add options for
ftltest.Context()
to set it up and tear it down at the end of the test.It should probably follow the pattern of how the fakes for verbs are done:
Map
calls under testing will panicMap
calls to pass throughThese three will give full control.
We'll need to do something like:
FTL.CallMap(ctx context.Context, mapper any) (any, error)
method to theFTL
interfacemockMaps
toftltest.OptionsState
newFakeFTL()
to take in themockMaps
ftltest.Context()
to achieve the aboveftl.Map.Get
implementation with one that uses theFTL
interfaceI think the API would be something like:
The text was updated successfully, but these errors were encountered: