Real-time Chat Examples β
Messaging patterns and real-time communication testing.
π Example Location β
examples/basic-examples/real-time-chat/
βββ server/ # Go gRPC server implementation
βββ tests/ # .gctf test files
βββ README.md # Setup instructionsπ― Test Scenarios β
Send Message β
Basic message sending with validation:
php
--- ADDRESS ---
localhost:4770
--- ENDPOINT ---
chat.ChatService/SendMessage
--- REQUEST ---
{
"room_id": "room_001",
"user_id": "user_123",
"message": "Hello, world!",
"timestamp": "2024-01-01T12:00:00Z"
}
--- RESPONSE ---
{
"message_id": "msg_456",
"room_id": "room_001",
"user_id": "user_123",
"message": "Hello, world!",
"timestamp": "2024-01-01T12:00:00Z",
"status": "sent"
}
--- ASSERTS ---
.message_id | type == "string"
.room_id == "room_001"
.user_id == "user_123"
.status == "sent"Get Messages β
Retrieve chat history:
php
--- ADDRESS ---
localhost:4770
--- ENDPOINT ---
chat.ChatService/GetMessages
--- REQUEST ---
{
"room_id": "room_001",
"limit": 10,
"offset": 0
}
--- RESPONSE ---
{
"messages": [
{
"id": "msg_001",
"user_id": "user_123",
"message": "Hello!",
"timestamp": "2024-01-01T12:00:00Z"
},
{
"id": "msg_002",
"user_id": "user_456",
"message": "Hi there!",
"timestamp": "2024-01-01T12:01:00Z"
}
],
"total_count": 2
}
--- ASSERTS ---
.messages | length == 2
.messages[0].user_id == "user_123"
.messages[1].user_id == "user_456"
.total_count == 2Secure Chat with TLS β
Encrypted communication with TLS:
php
--- ADDRESS ---
localhost:4770
--- TLS ---
ca_cert: ./../server/tls/ca-cert.pem
cert: ./../server/tls/client-cert.pem
key: ./../server/tls/client-key.pem
server_name: localhost
insecure_skip_verify: false
--- ENDPOINT ---
chat.ChatService/SendMessage
--- REQUEST ---
{
"room_id": "secure_room",
"user_id": "user_789",
"message": "Secret message",
"encrypted": true
}
--- RESPONSE ---
{
"message_id": "msg_789",
"room_id": "secure_room",
"user_id": "user_789",
"message": "Secret message",
"encrypted": true,
"status": "sent_encrypted"
}
--- ASSERTS ---
.status == "sent_encrypted"
.encrypted == trueπ§ Running the Examples β
bash
# Navigate to the example
cd examples/basic-examples/real-time-chat
# Start GripMock server with stubs
gripmock -s stubs/ &
# Run all tests
../../grpctestify.sh tests/*.gctf
# Run specific test
../../grpctestify.sh tests/send_message.gctf
# Stop GripMock server
pkill gripmockπ Test Coverage β
This example demonstrates:
- β Message Operations - Send and retrieve messages
- β Room Management - Chat room functionality
- β User Context - User identification and validation
- β Timestamp Handling - Time-based message ordering
- β TLS Security - Encrypted communication
- β Message History - Pagination and retrieval patterns
π Learning Points β
- Message Patterns - Basic chat message handling
- Data Retrieval - Fetching message history
- Security - TLS for encrypted communication
- Validation - Message structure and content validation
- Real-time Concepts - Timestamp and ordering patterns
π Related Documentation β
- Testing Patterns - Learn advanced testing techniques
- Plugin Development - Extend functionality with custom plugins
- API Reference - Complete command and format reference