Support client.Apply() test expectations#645
Conversation
Controller runtime added `Apply` as a client operation, which is sugar around a patch operation. Testing with patch is a bit painful today as the test needs to provide the json bytes of the patch. Diffs in the expected and actual bytes are very annoying to debug. The Apply operation uses a runtime.ApplyConfiguration object which can hold semantic structure and should make failing tests easier to debug. The ExpectConfig object now has an `ExpectApplies` slice that is compared to the Apply operation recorded on the fake client for the test. Likewise, an "apply" action is reacted during client requests. The assertion compares the ApplyConfiguration object as a json map. Signed-off-by: Scott Andrews <scott@andrews.me>
| } | ||
|
|
||
| func (*differ) ApplyRef(expected, actual ApplyRef) string { | ||
| return cmp.Diff(expected, actual, NormalizeApplyConfiguration) |
There was a problem hiding this comment.
normalizing the ApplyConfiguration as json is technically correct, but I wonder if the usability cost is too high as all other type info on the object being compared is lost.
A user can define a custom differ to change the behavior, but I'm wondering if the default should be to not apply the NormalizeApplyConfiguration transformer.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #645 +/- ##
==========================================
+ Coverage 56.96% 57.34% +0.38%
==========================================
Files 37 38 +1
Lines 4431 4504 +73
==========================================
+ Hits 2524 2583 +59
- Misses 1799 1807 +8
- Partials 108 114 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| type DeleteAction = clientgotesting.DeleteAction | ||
| type DeleteCollectionAction = clientgotesting.DeleteCollectionAction | ||
|
|
||
| type ApplyAction interface { |
There was a problem hiding this comment.
Defining a new action locally because "apply" isn't an api action in client-go.
Controller runtime added
Applyas a client operation, which is sugar around a patch operation. Testing with patch is a bit painful today as the test needs to provide the json bytes of the patch. Diffs in the expected and actual bytes are very annoying to debug. The Apply operation uses a runtime.ApplyConfiguration object which can hold semantic structure and should make failing tests easier to debug.The ExpectConfig object now has an
ExpectAppliesslice that is compared to the Apply operation recorded on the fake client for the test. Likewise, an "apply" action is reacted during client requests. The assertion compares the ApplyConfiguration object as a json map.