bot
bot copied to clipboard
Reduce cyclomatic complexity in handler.match() and 100% test coverage for handlers.go
Problem
- Closes #221
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.gofile.
:warning: Please install the to ensure uploads and comments are reliably processed by Codecov.
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 47.85%. Comparing base (1efca4f) to head (ddec830).
:warning: Report is 1 commits behind head on main.
:exclamation: 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
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.