-
Notifications
You must be signed in to change notification settings - Fork 18
Panics when comparing objects with unexported fields #484
Comments
when using cmp package with protobuf you'll need to use https://pkg.go.dev/google.golang.org/protobuf/testing/protocmp Unsure how to wire that option into reconciler-runtime testing |
I have the following snippet in my reconciler code which works when the comparator used in the code is from the
As @dprotaso points out - I also don't see how I can add this comparator when the lib is directly using Can the library be updated to provide custom comparators through init function? |
I am thinking we can add a property called Comparators in the testing and reconcilers package:
And update the existing
The following would be the usage in the test file:
|
@neowulf when you say (emphasis mine)
do you mean that your tests perform as expected or your reconciler works as expected? I assume the latter but want to double-check. As for a solution, I appreciate your idea concerning comparators. However, I am thinking more of something similar to We have a reconciler that stashes func verifyStashedValue(t *testing.T, key reconcilers.StashKey, expected, actual interface{}) {
if diff := cmp.Diff(expected, actual, cmp.AllowUnexported(big.Int{})); diff != "" {
t.Errorf("Unexpected stash value %q (-expected, +actual): %s", key, diff)
}
} A similar approach could be extended to The naive type VerifyExpectCreatesFunc func(t *testing.T, expected, actual []client.Object)
// or
type VerifyExpectCreatesFunc func(expected, actual []client.Object) error might require the user to be very diligent in reimplementing what https://github.com/vmware-labs/reconciler-runtime/blob/main/testing/config.go#L369-L391 does for them. But it could work. This should then be replicated for all the CRUD ops. Unless there's a simpler way. I might be able to draft this for you, but it might take a moment. |
type VerifyExpectCreatesFunc func(expected, actual client.Object) error might be simpler. reconciler-runtime would continue to assert the cardinality of expected and actual creates. It would call the user-provided |
Sorry for the confusion. Yes, that snippet is for the reconcilers to run. This bug is regarding the tests. My test setup is failing when I define the expected as part of the |
Should be resolved by #487 |
Describe the bug
reconciler-runtime: v0.18.0
Panic occurs when Istio types are used in the Reconciler tests.
Reproduction steps
Provide an Istio data type in the
ExpectCreates
"Expected behavior
Panic should not occur.
Additional context
Open to alternative ways of normalizing the istio data types to something the library can understand.
Passing in the unstructured struct doesn't seem to help because of the differing data types:
Background
Istio datatypes internally wrap protobuf messages in their k8s datatypes:
The text was updated successfully, but these errors were encountered: