Skip to content

Chat Unit Test added for 2 distinc functions - #21

Merged
huseynovvusal merged 3 commits into
huseynovvusal:mainfrom
Riad374-code:unit-test-chat
Apr 13, 2026
Merged

Chat Unit Test added for 2 distinc functions#21
huseynovvusal merged 3 commits into
huseynovvusal:mainfrom
Riad374-code:unit-test-chat

Conversation

@Riad374-code

@Riad374-code Riad374-code commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

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

Copilot AI review requested due to automatic review settings March 30, 2026 16:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 TestSendChatMessage to validate UDP send + JSON decoding.
  • Added TestListenForChatMessages intended to validate UDP receive path via ListenForChatMessages.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/chat/chat_test.go
Comment on lines +14 to +16
// 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.

Copilot AI Mar 30, 2026

Copy link

Choose a reason for hiding this comment

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

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).

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@Riad374-code please, consider this even if it is not that important.

Comment thread internal/chat/chat_test.go
Comment on lines +62 to +67
srvrAddr := &net.UDPAddr{
IP: net.ParseIP("127.0.0.1"),
Port: config.CHAT_PORT,
}

conn, err := net.DialUDP("udp", nil, srvrAddr)

Copilot AI Mar 30, 2026

Copy link

Choose a reason for hiding this comment

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

Variable name srvrAddr is abbreviated and harder to read. Prefer a clearer name like serverAddr to match typical Go style.

Suggested change
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)

Copilot uses AI. Check for mistakes.
Comment thread internal/chat/chat_test.go Outdated
Comment thread internal/chat/chat_test.go
Comment thread internal/chat/chat_test.go Outdated
Comment thread internal/chat/chat_test.go
Comment thread internal/chat/chat_test.go
@huseynovvusal
huseynovvusal self-requested a review March 31, 2026 03:44

@huseynovvusal huseynovvusal left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@Riad374-code good, but needs some improvements. Please, consider comments from Copilot. Additionally, don't forget to do go vet ./...

Comment on lines +14 to +16
// 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.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@Riad374-code please, consider this even if it is not that important.

Comment thread internal/chat/chat_test.go
Comment thread internal/chat/chat_test.go
Comment thread internal/chat/chat_test.go Outdated
Riad374-code and others added 2 commits March 31, 2026 15:27
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@huseynovvusal

Copy link
Copy Markdown
Owner

@Riad374-code, sorry, why you closed the PR?

@huseynovvusal huseynovvusal reopened this Mar 31, 2026
@huseynovvusal
huseynovvusal self-requested a review March 31, 2026 19:01
@huseynovvusal
huseynovvusal merged commit 590ecde into huseynovvusal:main Apr 13, 2026
1 check failed
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.

[TEST] Unit tests for internal/chat

3 participants