test: add unit tests for pkg/fileutil and pkg/health#1829
Open
perhapzz wants to merge 2 commits intosipeed:mainfrom
Open
test: add unit tests for pkg/fileutil and pkg/health#1829perhapzz wants to merge 2 commits intosipeed:mainfrom
perhapzz wants to merge 2 commits intosipeed:mainfrom
Conversation
…server Add comprehensive test coverage for two previously untested packages: pkg/fileutil (9 tests): - Basic write and read-back - File permissions (0600) - Overwrite existing files - Empty data handling - Nested directory auto-creation - No temp files left after success - Large file (1MB) handling - Concurrent write safety - Invalid path error handling pkg/health (15 tests): - Health endpoint returns 200 with status, uptime, pid - Ready endpoint returns 503 when not ready - Ready endpoint returns 200 when ready - Ready fails when any registered check fails - Ready passes with all checks passing - Reload rejects non-POST methods - Reload returns 503 when no reload func set - Reload calls registered function on success - Reload returns 500 on function error - SetReady toggle behavior - Multiple health checks interaction - RegisterOnMux works with custom ServeMux - NewServer defaults - StartContext graceful shutdown on cancel - statusString helper
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.
📝 Description
Add comprehensive unit test coverage for two packages that previously had zero tests:
pkg/fileutil(9 tests) — atomic file write operationspkg/health(15 tests) — health/ready/reload HTTP endpoints🗣️ Type of Change
🤖 AI Code Generation
🔗 Related Issue
No existing issue — discovered during code review that these two core packages had 0% test coverage.
📚 Technical Context (Skip for Docs)
pkg/fileutil.WriteFileAtomicis used for config persistence on edge devices (SD cards, flash storage) andpkg/healthendpoints are critical for Docker/K8s deployments. Both deserve test coverage to prevent regressions.🧪 Test Environment
Test Details
pkg/fileutil— 9 tests:TestWriteFileAtomic_BasicTestWriteFileAtomic_PermissionsTestWriteFileAtomic_OverwriteTestWriteFileAtomic_EmptyDataTestWriteFileAtomic_CreatesParentDirsTestWriteFileAtomic_NoTempFileOnSuccessTestWriteFileAtomic_LargeFileTestWriteFileAtomic_ConcurrentTestWriteFileAtomic_InvalidPathpkg/health— 15 tests:TestHealthHandler_ReturnsOKTestReadyHandler_NotReadyTestReadyHandler_ReadyTestReadyHandler_FailedCheckTestReadyHandler_PassingCheckTestReloadHandler_MethodNotAllowedTestReloadHandler_NoReloadFuncTestReloadHandler_SuccessTestReloadHandler_ErrorTestSetReady_ToggleTestRegisterCheck_MultipleChecksTestRegisterOnMuxTestNewServerTestStartContext_CancellationTestStatusString📸 Evidence (Optional)
Click to view test output
☑️ Checklist