test: make the test suite path handling windows-safe - #607
Conversation
Several test path constructions assumed forward slashes and broke under the backslashed paths os.Getwd returns on Windows: - the buildPath helper shared by the background, compression, customfont and disablepagebreak examples and by the internal/cache and pkg/fontrepository tests cut the working directory down with a forward-slash string replacement that never matched, so the asset path pointed inside the test directory. Walking the right number of segments up with filepath.Join reaches the repository root on every platform. - pkg/core carried the same helper with a substring left over from a package move, dead on every platform; the replacement is dropped. - pkg/test walked up to .maroto.yml by splitting on forward slashes, so on Windows the walk collapsed to the filesystem root, the config was never loaded and the suite panicked on the nil singleton. Normalizing the working directory with filepath.ToSlash keeps the existing forward-slash walk working everywhere, since the Windows file APIs accept forward slashes. With these, go test ./... passes on Windows.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (8)
Included review availability: Your plan provides up to 8 included reviews per hour; 5 remain after this review. 📝 WalkthroughSummary by CodeRabbit
WalkthroughTest helpers now construct fixture paths with ChangesWindows test path handling
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This PR makes test asset and configuration path handling Windows-safe without changing production behavior. No actionable merge-blocking risk remains beyond normal checks and review. Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #607 +/- ##
=======================================
Coverage 96.01% 96.01%
=======================================
Files 65 65
Lines 2479 2479
=======================================
Hits 2380 2380
Misses 64 64
Partials 35 35
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Thanks! |
Description
Makes the test suite runnable on Windows.
go test ./...currently fails there in three ways, all from path constructions that assume forward slashes whileos.Getwd()returns backslashed paths:buildPathhelper shared by thebackground,compression,customfontanddisablepagebreakexamples and by theinternal/cacheandpkg/fontrepositorytests trims the working directory with a forward-slashstrings.ReplaceAllthat never matches on Windows, so the asset path points inside the test directory and the font/image file is not found. The helper now walks the right number of segments up withfilepath.Join, which reaches the repository root on every platform.pkg/corecarries the same helper with a leftover substring from a package move (pkg/core/entity), which matches on no platform; the dead replacement is dropped.pkg/testlocates.maroto.ymlby splitting the working directory on/. On Windows the walk collapses to the filesystem root, the config is never loaded, and the suite panics on the nil singleton. Normalizing the working directory withfilepath.ToSlashkeeps the existing forward-slash walk working everywhere, since the Windows file APIs accept forward slashes.Test-only change apart from the one line in
pkg/test; no behaviour change on Linux (the CI path). Verified on Windows 11:go test ./...passes with this change, and fails in the three ways above without it.Context: CodeRabbit flagged the non-portable
buildPathcopy that #604 adds; rather than fix one copy and leave five, #604 adopts the portable form for its own example and this PR aligns the existing ones.Related Issue
Closes #606. Follow-up to the review discussion on #604.
Checklist
func (<first letter of struct> *struct) method() {}name style.when,shouldnaming pattern.m := mocks.NewConstructor(t).m.EXPECT().MethodName()method to mock methods.example_test.go.make dodwith none issues pointed out bygolangci-lint