-
Notifications
You must be signed in to change notification settings - Fork 18
Allow custom assertions for stashed values #311
Conversation
Codecov ReportBase: 61.64% // Head: 61.55% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #311 +/- ##
==========================================
- Coverage 61.64% 61.55% -0.09%
==========================================
Files 17 17
Lines 2151 2154 +3
==========================================
Hits 1326 1326
- Misses 748 751 +3
Partials 77 77
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
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.
If the goal is to offer alternative validation for stashed values, I think we should offer a hook that is explicitly for validating stashed values.
Something like:
VerifyStashedValue: func(t *testing.T, key reconcilers.StashKey, expected, observed interface{}) {
if diff := cmp.Diff(expected, actual, ...); diff != "" {
t.Errorf("Unexpected stash value %q (-expected, +actual): %s", key, diff)
}
},
We can use the default function if a user doesn't specify an override.
testing/subreconciler.go
Outdated
@@ -238,6 +240,9 @@ func (tc *SubReconcilerTestCase) Run(t *testing.T, scheme *runtime.Scheme, facto | |||
if tc.Verify != nil { | |||
tc.Verify(t, result, err) | |||
} | |||
if tc.VerifyCtx != nil { | |||
tc.VerifyCtx(t, ctx) |
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.
this will allow for additional validation, but it won't suppress existing validation for stashed values.
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.
The two might co-exist since
// ExpectStashedValues ensures each value is stashed. Values in the stash that are not expected are ignored. Values in the stash that are not expected are ignored. [...]
And so one might combine the two to achieve the desired coverage.
db0b326
to
579d923
Compare
That would work for a single entry in the stash. What if a reconciler addresses multiple entries?
By "default function", do you mean:
|
The current diff is computed for each item in the stash independently.
The existing call to cmp.Diff Something like: if tc.VerifyStashedValue == nil {
tc.VerifyStashedValue = func(t *testing.T, key reconcilers.StashKey, expected, observed interface{}) {
if diff := cmp.Diff(expected, actual, IgnoreLastTransitionTime, SafeDeployDiff, IgnoreTypeMeta, IgnoreCreationTimestamp, IgnoreResourceVersion, cmpopts.EquateEmpty()); diff != "" {
t.Errorf("Unexpected stash value %q (-expected, +actual): %s", key, diff)
}
}
} |
@scothis I get it! You describe a function for verifying each entry listed in |
76a12e1
to
ee328bc
Compare
VerifyCtx
@scothis your suggestion in incorporated and reflected in the PR's title. Would you recommend to start testing the |
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.
looking good, a couple small tweeks inline
1895c54
to
e8bc6f8
Compare
@scothis Incorporated your suggestions. Thanks for reminding me of |
Custom assertions for stashed values are helpful when they require bespoke verification. For example: