-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Filter tests are fragile and hard to understand #11777
Comments
This issue is currently awaiting triage. If CAPI contributors determine this is a relevant issue, they will accept it by applying the The 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 kubernetes-sigs/prow repository. |
/kind cleanup |
What would you suggest? |
I don't have a concrete suggestion. As I wrote above I assume these tests have been written like this because there was no easier/simpler solution. I think we can't compare structs in the tests because the diff string is the object which the function under test must return. Right? |
I wonder if it's important to test the diff strings at all. Of course, we aren't unit testing the functionality of go-cmp here. Rather, we want to ensure functions such as |
These tests are verifying that the diff looks as expected and especially that we notice if anything changes in a way that affects these diffs, basically like a golden file (e.g. we add a new field to the KubeadmConfig CRD that would trigger rollouts after CAPI upgrade) |
Yes. I realize that testing the diff contents covers more potential problems than just the existence of a diff. The problem is that IMO the current state is very fragile. By the way, the go-cmp docs say the following:
I even vaguely remember the library randomizing tabs vs. spaces to actively prevent people from relying on stability there (not sure if that's still the case though). |
I would expect that our tests would not be stable if this would be the case. |
In my opinion we don't depend on this output being stable. But we do want to know if anything changes, either because we bump the library or because we add fields to the CRDs |
Relevant issue: google/go-cmp#344 I wonder what a custom reporter is. Maybe that's what gomega does and hence the tests don't fail at random. |
In any case, I opened this since I had a hard time fixing the broken tests while working on making some |
I don't think gomega injects a custom reporter into the go-cmp library behind our back :) |
Yeah, I couldn't find such a thing either. In the past I'm 90% sure I saw go-cmp replace tabs with spaces and vice versa at random to prevent me from programmatically comparing diffs. |
Maybe We definitely use it because the output is better than |
https://pkg.go.dev/github.com/onsi/gomega#BeComparableTo I was curious about the implementation, so here it is: |
Okay. I would say let's keep it as is /close |
@sbueringer: Closing this issue. In 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 kubernetes-sigs/prow repository. |
While working on a change in the bootstrap API I've encountered tests such as the following:
cluster-api/controlplane/kubeadm/internal/filters_test.go
Lines 535 to 554 in 010af7f
When such tests failed for me I found it very tricky to figure out what's wrong. This is because the tests check the correctness of a diff value that's returned as a string from the function under test and prints any mismatches to the developer as a diff of two diffs (returned string vs expected string). Here is a sample failure:
When the expected diff string contains a difference (namely lines with
+/-
), the output gets even more confusing since we now have two "layers" of diffs -- the diff representation in the two diff strings (expected and actual) and the diff between the two diff strings.In addition, the tests are sensitive to whitespace differences because we rely on string comparison rather than semantic equivalence of two data structures.
I assume there was a good reason for writing these tests like this in the first place. However, I wonder if we can simplify these, get rid of relying on comparing strings somehow or find another way to make these tests less fragile and easier to debug.
cc @sbueringer
The text was updated successfully, but these errors were encountered: