-
Notifications
You must be signed in to change notification settings - Fork 9
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
refactor: centralise config/secrets/dbs/mocks into ModuleContext #1395
Conversation
@@ -60,6 +55,64 @@ func TestManager(t *testing.T) { | |||
}) | |||
} | |||
|
|||
// TestMapPriority checks that module specific configs beat global configs when flattening for a module | |||
func TestMapPriority(t *testing.T) { |
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.
moved from module_context_test.go
@@ -1,8 +0,0 @@ | |||
[global] |
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.
Removed because config/secret behavior is no longer tightly tied to project files
// This is useful for testing and development, where the environment is used to provide | ||
// configurations, secrets and DSNs. The context is built from a combination of | ||
// the ftl-project.toml file and (for now) environment variables. | ||
func FromEnvironment(ctx context.Context, module string, isTesting bool) (*ModuleContext, error) { |
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.
moved from module_context.go
247e043
to
1b31a1d
Compare
// configurations, secrets and DSNs. The context is built from a combination of | ||
// the ftl-project.toml file and (for now) environment variables. | ||
func FromEnvironment(ctx context.Context, module string, isTesting bool) (*ModuleContext, error) { | ||
// TODO: split this func into separate purposes: explicitly reading a particular project file, and reading DSNs from environment |
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.
Related to this issue: #1391
1b31a1d
to
658ea91
Compare
if mock, ok := m.mockVerbs[ref]; ok { | ||
return MockBehavior{Mock: mock}, nil | ||
} | ||
// TODO: add logic here for when to do direct behavior |
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.
Will be done in this PR after it rebases on this one: #1373
) | ||
|
||
type Ref 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.
Can we use a schema.RefKey
here? We're proliferating Ref
s for no real reason I think, so I'm trying to consolidate them. schema.Ref
has a method to retrieve a RefKey
.
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.
Will do 👍
return moduleCtx | ||
} | ||
|
||
func FromContext(ctx context.Context) *ModuleContext { |
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.
Comments.
Please add useful comments to all code going into go-runtime.
} | ||
|
||
// SetSecret sets a secret value for the module. | ||
func (m *ModuleContext) SetSecret(name string, value any) error { |
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.
Do we nede setters? Can we not make the ModuleContext immutable?
If we don't, it will need locks because it could be accessed from multiple threads, but I'd vastly prefer it to be immutable.
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.
Will make another issue for that
return resp, fmt.Errorf("%s: %w", callee, err) | ||
} | ||
switch behavior := behavior.(type) { | ||
case modulecontext.MockBehavior: |
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.
Instead of a switch in the call
function with logic in each case, move the logic into the respective VerbBehaviour
implementations. A general pattern to watch for is that if significant logic around a "switch" is occurring outside the thing being switched on it might be time to encapsulate that logic into a method.
configuration
package in go-runtimecall.go
now asks ModuleContext for any custom behaviour as required by the test set up. This includes verb mocks, whether to allow calling the verb directly, or custom errors in testing environments