Skip to content

Add tests for panic behavior on malformed route patterns#1066

Open
fheikens wants to merge 2 commits into
go-chi:masterfrom
fheikens:panic-tests
Open

Add tests for panic behavior on malformed route patterns#1066
fheikens wants to merge 2 commits into
go-chi:masterfrom
fheikens:panic-tests

Conversation

@fheikens

Copy link
Copy Markdown

Summary

Adds test coverage for five existing panic guard paths in route pattern
validation that were not explicitly covered by tests. No production code was changed.

Covered cases:

  • Unclosed { brace in route pattern (tree.go:patNextSegment)
  • Duplicate parameter keys in pattern (tree.go:patParamKeys) — addresses the TODO at tree_test.go:194
  • Invalid regexp in route parameter (tree.go:addChild)
  • Route() called with nil function (mux.go:Route)
  • Mount() called with nil handler (mux.go:Mount)

Test plan

  • All five new tests pass: go test -v -run TestPanic ./...
  • Full test suite passes: go test ./...
  • No production code modified

@themavik themavik left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good coverage of router construction panics (unclosed {, duplicate {id}, bad regexp, nil Route/Mount). nit: TestPanicOnInvalidRegexp uses {id:[invalid}—if that ever stops compiling for a different reason, the test name will lie; tighten the pattern if you see flakes.

…Compile

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@fheikens

Copy link
Copy Markdown
Author

Good point — tightened the pattern to {id:(abc} (unclosed group) so the failure is unambiguously from regexp.Compile, not from route pattern parsing. Test name stays accurate.

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