Improve fragmentation package test coverage#114
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #114 +/- ##
==========================================
+ Coverage 82.37% 90.12% +7.74%
==========================================
Files 43 43
Lines 2951 2946 -5
==========================================
+ Hits 2431 2655 +224
+ Misses 390 232 -158
+ Partials 130 59 -71 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| Expect(cache.order.Len()).Should(Equal(0)) | ||
| }) | ||
|
|
||
| It("should discard an invalid usage-order entry", func() { |
There was a problem hiding this comment.
This spec (and the "usage order is empty" one above) exercises branches in cache.evictOldest() — the Front() == nil guard and the !isKey type-assertion fallback — that are unreachable in production: order only ever receives K-typed keys via storeLoaded → PushBack(key), and evictOldest is only ever called right after a PushBack, so the list is never empty and the assertion never fails. To cover them the test has to hand-craft an impossible state (order.PushBack("not an int key")). Worth considering whether the defensive branches are dead code that should be dropped rather than propped up with tests.
| // It points to os.Stat in production. Tests replace it to exercise error | ||
| // handling after glob resolution, which otherwise depends on filesystem races | ||
| // between finding a path and inspecting it. | ||
| var statPath = os.Stat |
There was a problem hiding this comment.
Minor / design: this (and makeAbsolutePath in fragmentation.go:63) introduces a mutable package-global into production code purely as a test seam. It works and is well-documented, and since Ginkgo parallelism is process-based the global mutation is safe. Just flagging the tradeoff for the record — an alternative that keeps production surface immutable would be injecting the stat/abs function through the existing struct (e.g. Resolver/Fragmentation) rather than a reassignable global. Not blocking.
Oleg-Melnik
left a comment
There was a problem hiding this comment.
@Vladyslav-Kuksiuk LGTM with comments to address.
This PR improves
fragmentationandfilespackages test coverage.