Add comprehensive unit tests for contract, router, and problem modules#7
Merged
Merged
Conversation
… helpers Cover all functions in contract root (sentinel errors, context keys), request/ (body, cookie, header, hooks, param, query, session), and response/ (static, stream) subpackages achieving 100% statement coverage on request and response packages.
Add 57 test functions covering all HTTP method shortcuts, middleware execution order, group/clone/with sub-routers, pattern registration (trailing slash, root, catch-all), Handler/HandlerMatch, and Record. Remaining 3.3% is unreachable dead code in registerPair.
Add 55 tests for problem.go (constructors, additional CRUD, error wrapping, stack traces, JSON marshal/unmarshal, content negotiation, HTTP handlers), 6 tests for utils.go (stackTrace with nil, simple, wrapped, and joined errors), and 7 tests for internal/accept.go (Quality, malformed media, empty accept) bringing internal from 86.8% to 100%.
…rPair path.Join in Method() always strips trailing slashes before patterns reach registerPair, making the CutSuffix branch dead code. Removing it brings router coverage from 96.7% to 100%.
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
registerPair)Contract Module (13 new test files)
request/: body parsing (JSON, XML, bytes, limited variants), cookies, headers, params, query strings, hooks, sessionsresponse/: static responses (Raw, JSON, XML, HTML, templates, redirects, SafeRedirect), streaming (Stream, SSE, context cancellation, non-flushable writer)Router Module (57 new tests + dead code removal)
CutSuffixbranch inregisterPair(path.Joinalways strips trailing slashes)Problem Module (68 new tests across 3 files)
problem_test.go: constructors, additional field CRUD, error wrapping, stack traces, JSON marshal/unmarshal, HTTP content negotiation, all three response handlersutils_test.go:stackTracewith nil, simple, wrapped, and joined errorsinternal/accept_test.go: Quality method, malformed media types, empty accept, wildcard matching