Add tests and refinements for config --create#273
Merged
Conversation
Build on PR #272's createConfig() contribution with test coverage and improvements: - Promote config path constants to package level so initConfig() and createConfig() share a single source of truth - Introduce configFS interface for testability with fully in-memory mock filesystem (no real FS access during tests) - Use O_EXCL flag for atomic file creation instead of stat-then-write - Trim leading newline from exampleConfig when writing to disk - Handle f.Close() error via named return (errcheck compliance) - Add 8 comprehensive TestCreateConfig_* tests covering success path, content trimming, correct paths/flags/perms, and all error branches Created with assistance from Claude 🤖 <claude@anthropic.com> Signed-off-by: Christopher Collins <collins.christopher@gmail.com>
Clarify that `srepd config --create` creates a config file (not just prints a sample) to match the behavior added in PR #272. Created with assistance from Claude 🤖 <claude@anthropic.com> Signed-off-by: Christopher Collins <collins.christopher@gmail.com>
Codecov Report❌ Patch coverage is
❌ Your patch status has failed because the patch coverage (45.45%) is below the target coverage (70.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #273 +/- ##
==========================================
+ Coverage 69.76% 70.06% +0.30%
==========================================
Files 34 34
Lines 4869 4868 -1
==========================================
+ Hits 3397 3411 +14
+ Misses 1263 1246 -17
- Partials 209 211 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The osFS struct delegates directly to os.MkdirAll and os.OpenFile with no logic — tested indirectly via the mockFS-based unit tests that exercise createConfig through the configFS interface. Created with assistance from Claude 🤖 <claude@anthropic.com> Signed-off-by: Christopher Collins <collins.christopher@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Builds on the great work from PR #272's
createConfig()contribution with test coverage and a few improvements:cfgFileName,cfgFileDir) to package level soinitConfig()andcreateConfig()share a single source of truth, and updatesinitConfig()to usefilepath.Joinfor consistencyconfigFSinterface socreateConfig()can be tested with a fully in-memory mock filesystem — no real filesystem access during testsO_EXCLflag for atomic create-or-fail instead of a separate stat-then-write patternexampleConfigwhen writing to disk so the file starts with the#comment lineTestCreateConfig_*coverage for success path, content trimming, correct paths/flags/permissions, and all error branchesTest plan
make fmt-check— cleanmake vet— cleangolangci-lint run— 0 issuesmake test— all pass including 8 new TestCreateConfig_* testsmake test-race— no racesmake test-coverage-threshold— 72.8% (threshold: 55%)🤖 Generated with Claude Code