Skip to content

Reduce cyclomatic complexity in handler.match() and 100% test coverage for handlers.go - #222

Closed
steindvart wants to merge 6 commits into
go-telegram:mainfrom
steindvart:Steindvart/handlers-refactor-and-tests
Closed

steindvart wants to merge 6 commits into
go-telegram:mainfrom
steindvart:Steindvart/handlers-refactor-and-tests

Conversation

@steindvart

@steindvart steindvart commented Oct 28, 2025 •

Copy link
Copy Markdown
Contributor

Problem

Solution - what PR does

  • Comprehensive decomposition of the function (h handler) match(update *models.Update). To reduce cyclomatic complexity, and improve testability.

Now, for handlers.go file, the following indicators apply:

$ gocyclo handlers.go
9 bot getDataFromUpdate handlers.go:72:1
9 bot (handler).match handlers.go:44:1
5 bot (handler).matchCommandStartOnly handlers.go:137:1
4 bot (handler).matchCommand handlers.go:125:1
4 bot extractCommand handlers.go:116:1
3 bot (*Bot).UnregisterHandler handlers.go:205:1
1 bot (*Bot).RegisterHandler handlers.go:186:1
1 bot (*Bot).RegisterHandlerRegexp handlers.go:167:1
1 bot (*Bot).RegisterHandlerMatchFunc handlers.go:149:1
1 bot (handler).matchRegexp handlers.go:112:1
1 bot (handler).matchContains handlers.go:108:1
1 bot (handler).matchPrefix handlers.go:104:1
1 bot (handler).matchExact handlers.go:100:1

Previous:

$ gocyclo handlers.go                                                                                                                                                               
23 bot (handler).match handlers.go:43:1
3 bot (*Bot).UnregisterHandler handlers.go:165:1
1 bot (*Bot).RegisterHandler handlers.go:146:1
1 bot (*Bot).RegisterHandlerRegexp handlers.go:127:1
1 bot (*Bot).RegisterHandlerMatchFunc handlers.go:109:1
  • Achieving 100% branch coverage for the all added code.
  • Achieving 100% test coverage for the handlers.go file.
image

@codecov-commenter

codecov-commenter commented Oct 28, 2025 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 47.85%. Comparing base (1efca4f) to head (ddec830).
⚠️ Report is 12 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #222      +/-   ##
==========================================
+ Coverage   45.30%   47.85%   +2.54%     
==========================================
  Files          29       29              
  Lines        2355     2123     -232     
==========================================
- Hits         1067     1016      -51     
+ Misses       1241     1063     -178     
+ Partials       47       44       -3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

negasus added a commit that referenced this pull request Oct 4, 2026
Incorporate the handler decomposition and tests from PR #222. Use success flags for update and command extraction, avoid allocations for absent update data, and reject invalid command bounds without overflow or empty-pattern matches.

Co-authored-by: Ivan Kalashnikov <ivank.public@gmail.com>
@negasus

negasus commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Implemented in #304, which has been merged into main. The handler decomposition and tests from this PR were included, with additional command-boundary validation and allocation-free success flags. Your contribution is credited in the merged commit with a Co-authored-by trailer. Thank you for the refactoring and tests!

@negasus negasus closed this Oct 4, 2026
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.

Reduce cyclomatic complexity in handler.match() (handlers.go, line 43)

3 participants