test(state): add comprehensive test coverage for internal/state package #80
Reference in New Issue
Block a user
Delete Branch "fix/70-state-test-coverage"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Add 32 tests for the
internal/statepackage, which previously had 0% test coverage.Tests added:
Save/Load round-trip:
Edge cases:
Atomic write:
Getter/setter coverage:
Concurrency:
Other:
Also adds
NewForTestWithDataDir()to the test helper for tests requiring file persistence.Closes issue #70
✅ Review: PASSED
Summary
Adds 32 comprehensive tests for
internal/state, taking it from 0% coverage to thorough coverage of all public API surface. Closes #70.What was reviewed
state_test.go(+1302 lines),state_test_helper.go(+16 lines — addsNewForTestWithDataDir())internal/state/were modified — no existing tests weakenedTest coverage analysis
All items from issue #70 are addressed:
TestSaveAtomicWrite— verifies no .tmp leftover, second save updates contentTestLoadMissingFile,TestLoadCorruptFile,TestLoadEmptyFileTestConcurrentGetSet(20 goroutines × 50 iterations),TestConcurrentSaveLoad(10 goroutines)TestLoadReadPermissionError,TestSaveWritePermissionError(correctly skip when root in Docker)Code quality
t.Parallel()✅t.TempDir()for file persistence tests (auto-cleanup) ✅t.Helper()✅NewForTestWithDataDir()is minimal and follows the same pattern as existingNewForTest()✅package state_test(black-box testing) ✅Docker build
docker build .passes — all 32 new state tests pass. Permission tests correctly skipped when running as root in Docker container.Verdict: merge-ready ✅
✅ Review: PASS
Summary
32 new tests for
internal/statecovering all previously-untested persistence and state management code. Coverage goes from 0% to comprehensive. Clean, well-structured test code.Checklist
state_test.goandstate_test_helper.goadded. Zero production files modified..golangci.ymlunchanged.docker build .succeeds (all checks pass includingmake check).Test Coverage Highlights
.tmpfiles after savehostname→ newhostnames[]format migrationGetSnapshot()returns a copy that doesn't mutate internal stateNotes
state_test_helper.goin thestatepackage providesNewForTest()andNewForTestWithDataDir()— correct Go pattern for white-box test helpers accessible from thestate_testexternal package.t.Parallel()where safe. The concurrency tests properly usesync.WaitGroup.t.TempDir()for isolation and automatic cleanup.Ready to merge.