OTA-1159: [1/x] Refactor syncStatus for testability#1031
Conversation
I would like to unit-test this logic but `syncStatus` does apiserver operation so such tests would need a fake. Computing new status is enough logic to constitute a method, so we can extract it so that we can test it without a mock server. Extracted with an IDE refactor helper.
`Operator` is a pretty beefy object with access to half of the universe, but `updateClusterVersionStatus` only uses its member very little. It reads its `release` member and calls its `getAvailableUpdates` method. We can uncouple the long method by passing these two members as parameters. It is slightly awkward for the `getAvailableUpdates` method but I think the benefits outweight this.
Status-computing methods can only read and modify `ClusterVersionStatus` instead of `ClusterVersion`, resulting in simpler code and lower chance of making a mistake.
|
@petr-muller: This pull request references OTA-1159 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.16.0" version, but no target version was set. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: petr-muller, wking The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/retest No pre-merge testing necessary, will get solid amount of testing after merge |
|
@petr-muller: all tests passed! Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
|
[ART PR BUILD NOTIFIER] This PR has been included in build cluster-version-operator-container-v4.16.0-202401311812.p0.gce6169c.assembly.stream for distgit cluster-version-operator. |
updateClusterVersionStatus: add godoc and linewrap signature
status: work with
ClusterVersionStatusinstead ofClusterVersionStatus-computing methods can only read and modify
ClusterVersionStatusinstead of
ClusterVersion, resulting in simpler code and lower chanceof making a mistake.
status: uncouple
updateClusterVersionStatuswithOperatorOperatoris a pretty beefy object with access to half of the universe, butupdateClusterVersionStatusonly uses its member very little. It reads itsreleasemember and calls itsgetAvailableUpdatesmethod.We can uncouple the long method by passing these two members as parameters. It is slightly awkward for the
getAvailableUpdatesmethod but I think the benefits outweight this.status: extract status update logic to method
I would like to unit-test this logic but
syncStatusdoes API operation so such tests would need a fake. Computing new status is enough logic to constitute a method, so we can extract it so that we can test it without a mock server.Extracted with an IDE refactor helper.