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 crtb and prtb manager to make it more testable #45433
Refactor crtb and prtb manager to make it more testable #45433
Conversation
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.
Thank you for making the effort here to make the system more testable.
I like the approach very much. Especially as it means that only the high-level
functions need mocking instead of deeper details. This makes tests much simpler.
The only thing I am missing is the equivalent work for the
pkg/controllers/managementuser/rbac/[cp]rtb_handler.go
.
That however is something I could do as part of my work on the CRTB status field.
I wholeheartedly approve this PR.
Despite effectively undoing the test work I did for the status field.
…asic tests for examples
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.
Approving again.
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.
a big improvement, lgtm
Summary
As it currently stands, there are no unit tests for
crtb_handler.go
orprtb_handler.go
. Part of the reason for that is that the code is set up in a way that is very difficult to test. This PR is a potential refactor that makes the code much more testable. It is important to note that this is just a code refactor, with no changes to functionality.Commits
I tried as best I could to split the commits into logical blocks to help reviewers
manager.go
tocrtb_handler.go
. That way, the manager struct is only referenced to access it's functions, not it's fields.prtb_handler.go
manager.go
, remove any unused clients from themanager
structmanagerInterface
that contains all the functions used bycrtb_handler.go
prtb_handler.go
crtb_handler.go
where we mock themanagerInterface
manager
and added almost full test coverage ofreconcileBindings
managementuser
Future work:
manager
functions really don't need to be member functions, which would simplify the mock. Often these functions reference a single field frommanager
, which we could pass in when the function is called instead.DO NOT MERGE
This is a for example purposes only. After discussion it may get merged.