Add comprehensive test coverage for bot command functions #71
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.
This PR adds extensive test coverage for the bot command functions, following the existing test patterns established in
react_test.go
. The test suite covers 9 command modules with 33 total tests, ensuring robust validation of command functionality and response handling.Added Test Files
caffeine_test.go
- Tests caffeine injection command with numeric input validationapb_test.go
- Tests "all points bulletin" command with user lookup scenarioss_test.go
- Tests string replacement command with format validationreload_test.go
- Tests bot reload/shutdown command and help functionssay_test.go
- Tests echo command functionalityemote_test.go
- Tests/me
emote action commandroll_test.go
- Tests dice rolling with regex validation for random outputsthought_test.go
- Tests help function (main function requires HTTP refactoring)type_test.go
- Tests command type constantsTest Infrastructure Improvements
Enhanced Cache Mocking: Created
MockCacheWithUser
that extends the existingMockCache
to properly handle user data injection for testing user-dependent commands.Channel-based Response Testing: Implemented proper goroutine handling with timeouts to test asynchronous response channel communication, ensuring tests don't hang on failed responses.
Regex Validation: Added pattern matching for commands with random outputs (like dice rolls) to validate correct format while allowing for randomness.
Issues Identified During Testing
Found two potential bugs in the existing codebase:
caffeine.go
: When invalid numeric input is provided, the command sends an empty response message instead of falling back to the default messages.go
: When string replacement format is invalid, the function returns early without sending the intended DM response to the channelTest Results
All 33 tests pass successfully (31 run, 2 skipped for HTTP testing that requires refactoring). The test suite follows Go best practices with table-driven tests and maintains consistency with existing repository patterns.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.