Overload constructors for ClusterState and DestinationState to enable unit testing#2198
Merged
Tratcher merged 1 commit intodotnet:mainfrom Jul 24, 2023
Merged
Conversation
Contributor
Author
|
@microsoft-github-policy-service agree |
Tratcher
approved these changes
Jul 24, 2023
Member
|
Thanks |
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.
This addresses two open issues, #2142 and #1792, related to difficulties in unit testing custom middleware due to the inability to initialize/modify ClusterState and DestinationState.
The
ClusterStateandDestinationStateconstructors are now overloaded to accept additional parameters, which enables better unit testing when updating theReverseProxyFeatureviaHttpContextFeaturesExtensions.However it's worth noting that lifting these restrictions may allow the user to set the state in the
ReverseProxyFeaturethat may potentially cause unintended side effects. Once I started diving deeper into the code, it seemed that there is some level of dependency on the immutable design, as there is logic related to making the state eventually consistent; I believe that's why there is some duplicate data such as the clusterId and destination configurations in the nested objects ofClusterState. But it seems that this potential risk was present before these changes, so it's most likely acceptable in a unit testing context.Here is a sample of leveraging these new constructors in the context of the two open issues
These changes offer better granularity for unit testing through reassigning the
ReverseProxyFeaturewith aClusterState, via creating/modifying theClusterModelalong with itsClusterConfig, and theDestinationStates of theAllDestinationsandAllDestinationsproperties with their associatedDestinationModels andDestinationConfigs.