Chat Unit Test added for 2 distinc functions - #21
Conversation
There was a problem hiding this comment.
Pull request overview
Adds initial unit/integration tests for the chat UDP send and listen paths to improve coverage around SendChatMessage and ListenForChatMessages.
Changes:
- Added
TestSendChatMessageto validate UDP send + JSON decoding. - Added
TestListenForChatMessagesintended to validate UDP receive path viaListenForChatMessages.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // This function is a placeholder for testing SendChatMessage. | ||
| // In a real test, you would set up a mock UDP server to receive the message | ||
| // and verify that the content and sender information are correct. |
There was a problem hiding this comment.
The comment says this is a “placeholder” test, but the code is an actual integration-style UDP test. This is misleading and will age poorly; either remove/reword the comment to describe what the test really validates, or implement the additional assertions it claims are missing (e.g., sender info).
There was a problem hiding this comment.
@Riad374-code please, consider this even if it is not that important.
| srvrAddr := &net.UDPAddr{ | ||
| IP: net.ParseIP("127.0.0.1"), | ||
| Port: config.CHAT_PORT, | ||
| } | ||
|
|
||
| conn, err := net.DialUDP("udp", nil, srvrAddr) |
There was a problem hiding this comment.
Variable name srvrAddr is abbreviated and harder to read. Prefer a clearer name like serverAddr to match typical Go style.
| srvrAddr := &net.UDPAddr{ | |
| IP: net.ParseIP("127.0.0.1"), | |
| Port: config.CHAT_PORT, | |
| } | |
| conn, err := net.DialUDP("udp", nil, srvrAddr) | |
| serverAddr := &net.UDPAddr{ | |
| IP: net.ParseIP("127.0.0.1"), | |
| Port: config.CHAT_PORT, | |
| } | |
| conn, err := net.DialUDP("udp", nil, serverAddr) |
huseynovvusal
left a comment
There was a problem hiding this comment.
@Riad374-code good, but needs some improvements. Please, consider comments from Copilot. Additionally, don't forget to do go vet ./...
| // This function is a placeholder for testing SendChatMessage. | ||
| // In a real test, you would set up a mock UDP server to receive the message | ||
| // and verify that the content and sender information are correct. |
There was a problem hiding this comment.
@Riad374-code please, consider this even if it is not that important.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@Riad374-code, sorry, why you closed the PR? |
Summary
Adds tests for SendChatMessage and ListenForChatMessages.
Improves reliability and reduces chat-related regressions.
Motivation
Chat send/listen behavior had low test coverage.
Needed safer future changes in networking code.
Solution
Added chat tests in internal/chat/chat_test.go.
Verifies message send flow and listener receive flow.
Testing
Commands run:
make test
go test ./...
go test ./internal/chat -v
Scenarios:
Message is sent and decoded correctly
Listener receives incoming UDP message
Closes: #15