Skip to content

Add tests and refinements for config --create#273

Merged
clcollins merged 3 commits into
mainfrom
srepd/config-create-enhancements
Jun 5, 2026
Merged

Add tests and refinements for config --create#273
clcollins merged 3 commits into
mainfrom
srepd/config-create-enhancements

Conversation

@clcollins

Copy link
Copy Markdown
Owner

Summary

Builds on the great work from PR #272's createConfig() contribution with test coverage and a few improvements:

  • Shared constants: Promotes config path constants (cfgFileName, cfgFileDir) to package level so initConfig() and createConfig() share a single source of truth, and updates initConfig() to use filepath.Join for consistency
  • Testable design: Introduces a configFS interface so createConfig() can be tested with a fully in-memory mock filesystem — no real filesystem access during tests
  • Atomic file creation: Uses O_EXCL flag for atomic create-or-fail instead of a separate stat-then-write pattern
  • Clean file output: Trims the leading newline from exampleConfig when writing to disk so the file starts with the # comment line
  • 8 new tests: Comprehensive TestCreateConfig_* coverage for success path, content trimming, correct paths/flags/permissions, and all error branches

Test plan

  • make fmt-check — clean
  • make vet — clean
  • golangci-lint run — 0 issues
  • make test — all pass including 8 new TestCreateConfig_* tests
  • make test-race — no races
  • make test-coverage-threshold — 72.8% (threshold: 55%)

🤖 Generated with Claude Code

clcollins added 2 commits June 5, 2026 08:09
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-commenter

codecov-commenter commented Jun 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 45.45455% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.06%. Comparing base (e02427e) to head (934d8ce).

Files with missing lines Patch % Lines
cmd/config.go 50.00% 8 Missing and 2 partials ⚠️
cmd/root.go 0.00% 2 Missing ⚠️

❌ 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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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>
@clcollins clcollins merged commit f164f3c into main Jun 5, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants