[test] Add comprehensive tests for server.handlers #486
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.
Test Coverage Improvement: server.handlers
Function Analyzed
internal/serverhandlers.gohandleOAuthDiscovery(),handleClose()Why This File?
This file was selected because:
The file contains 85 lines of production code implementing:
Tests Added
Created
internal/server/handlers_test.gowith 14 comprehensive test functions (441 lines):OAuth Discovery Tests
TestHandleOAuthDiscovery- Tests endpoint returns 404 for all HTTP methods (GET, POST, PUT, DELETE)Close Endpoint Tests
TestHandleClose_MethodValidation- Only POST requests accepted, others return 405TestHandleClose_SuccessfulShutdown- Proper JSON response structure on shutdownTestHandleClose_Idempotency- First request: 200 OK, subsequent: 410 GoneTestHandleClose_MultipleRequests- Concurrent requests handled without race conditionsTestHandleClose_ResponseFormat- JSON structure validation (status, message, serversTerminated)TestHandleClose_RemoteAddress- Remote address loggingTestHandleClose_EmptyBody- Works without request bodyTestHandleClose_WithRequestBody- Ignores request body contentTestShutdownErrorJSON- Validates shutdown error constant formatTestHandleClose_ShouldExitFlag- testMode flag controls os.Exit() behaviorCoverage Report
Test Execution
Tests follow project conventions:
assert,require)httptestfor HTTP handler testingUnifiedServerwithtestModeto preventos.Exit()Coverage Goals Achieved
Testing Best Practices
The tests demonstrate:
httptest.ResponseRecorderGenerated by Test Coverage Improver
Next Target: Based on analysis, the next high-priority untested files are:
internal/server/auth.go(~60 lines) - API key authentication middlewareinternal/middleware/jqschema.go(~220 lines) - JQ schema transformationinternal/server/sdk_logging.go(~120 lines) - JSON-RPC debugging