Skip to content
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

[Chore]: Backfill unit tests for repositories package #601

Closed
matt-royal opened this issue Jan 31, 2022 · 4 comments
Closed

[Chore]: Backfill unit tests for repositories package #601

matt-royal opened this issue Jan 31, 2022 · 4 comments
Assignees
Labels

Comments

@matt-royal
Copy link
Member

matt-royal commented Jan 31, 2022

Background

We've been feeling the pain of our integration-only strategy lately, and have been unable to test some common failure cases. We've already established patterns for testing the controllers with k8s client fakes, and we're confident we can do the same here.

Action to take

Find the // untested comments in the repositories package and backfill unit tests for those cases.

Impact

This will give us more confidence that we're properly implementing error handling, and also help us avoid regressions of untested behavior

Dev Notes

  • Start with CFServiceInstance and write chores for others
@gcapizzi
Copy link
Contributor

I would generally advice against mocking types we don't own, in this case the controller-runtime client. We'd be making assumptions about how the client (and the Kubernetes API) work, which might be wrong. It would allow us to test some particularly hard to reach error cases, but I could only find 3 instances of // untested in the repositories package, so maybe it's not that big of a deal? Overall I don't think it warrants the introduction of a new test suite.

@matt-royal
Copy link
Member Author

Thank you, @gcapizzi. I'll discuss this with the AMER team today. I agree that, if we add these, it only makes sense to test the // untested branches.

@gcapizzi
Copy link
Contributor

@matt-royal someone also pointed out that some // untested branches have been deleted because we have a coverage report now, not so easy to spot them via that webpage though 😕 I'm sure there's a way to extract all uncovered lines and extract error checks from them. We should probably be looking at all our uncovered lines anyway, but that is not necessarily related to this issue.

julian-hj added a commit that referenced this issue Mar 29, 2022
- This allows us to reach better code coverage for error cases
- We added interfaces for the namespace retriever and nsperms objects in
  order to make them fakeable.
- We added fakes for the client factory and client interfaces also.
- Minor typo and format fixes.

[#601]

Co-authored-by: Julian Hjortshoj <hjortshojj@vmware.com>
matt-royal added a commit that referenced this issue Mar 31, 2022
[#601]

Authored-by: Matt Royal <mroyal@vmware.com>
@julian-hj
Copy link
Member

We created a POC to add unit level tests to the existing suite, but it didn't get a lot of support, so we abandoned it. @georgethebeatle has another approach to try by adding an interface layer on top of the k8s cliet, but for now we will close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

No branches or pull requests

3 participants