refactor(fn): factor RunFunction into focused helpers - #44
Merged
Conversation
Several helpers on the Function struct don't use any receiver state, making them harder to test in isolation than they need to be. This commit converts them from methods to package-level functions. It also adds a NewFunction constructor that defaults a nil logger to a no-op implementation, preventing nil-pointer panics if a caller forgets to set the logger (e.g. in tests). Finally, structToSpecSchema's error wrapping is aligned with the rest of fn.go: fmt.Errorf with "failed to X" becomes errors.Wrap with "cannot X". Signed-off-by: Jared Watts <jbw976@gmail.com>
RunFunction mixed orchestration with inline implementation for several self-contained operations. This made the overall processing flow harder to follow and prevented testing those operations independently. This commit pulls the inline blocks into package-level functions so RunFunction reads as a linear sequence of helper calls and error handling. The helpers are ordered in the file to match the call sequence, so the file reads top-to-bottom like the processing flow. RunFunction no longer needs a gocognit suppression. Signed-off-by: Jared Watts <jbw976@gmail.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of your changes
This PR is an attempt to clean up the
fn.gopart of the code base a bit, as a result of running some of @negz golang related skills.The main
RunFunctionmixed orchestration with inline implementations, making the processing flow hard to follow and preventing independent testing of self-contained operations.This PR restructures the code we own (fn.go, fn_test.go, main.go) without changing any behavior:
NewFunctionconstructor that defaults nil loggers to no-op, preventing nil-pointer panics in testsrequireSchemas,externalCollectionSelector,groupObservedByNodeID)collectGVKs,buildDesiredComposed, andbuildDesiredXRStatussoRunFunctionreads as a linear sequence of helper calls and error handlingRunFunctionstructToSpecSchemawith the rest of the file (errors.Wrap/"cannot X"instead offmt.Errorf/"failed to X")RunFunctionno longer needs a gocognit suppression.I have: