#!/bin/bash # gRPC Endpoint Testing Script for Phase 1 # Requires grpcurl: brew install grpcurl (macOS) or see https://github.com/fullstorydev/grpcurl set -e GRPC_HOST="localhost:6000" GREEN='\033[0;32m' BLUE='\033[0;34m' YELLOW='\033[1;33m' NC='\033[0m' # No Color echo -e "${BLUE}================================${NC}" echo -e "${BLUE}Phase 1 gRPC Endpoint Tests${NC}" echo -e "${BLUE}================================${NC}" echo "" # Check if grpcurl is installed if ! command -v grpcurl &> /dev/null; then echo "❌ grpcurl is not installed" echo "Install with: brew install grpcurl (macOS)" echo "Or see: https://github.com/fullstorydev/grpcurl" exit 1 fi echo -e "${GREEN}✓ grpcurl is installed${NC}" echo "" # Check if server is running echo -e "${YELLOW}Checking if gRPC server is running...${NC}" if ! grpcurl -plaintext ${GRPC_HOST} list > /dev/null 2>&1; then echo "❌ gRPC server is not running on ${GRPC_HOST}" echo "Please start the application first: cd Svrnty.Sample && dotnet run" exit 1 fi echo -e "${GREEN}✓ gRPC server is running${NC}" echo "" # Test 1: List Services echo -e "${YELLOW}Test 1: List Available Services${NC}" echo "grpcurl -plaintext ${GRPC_HOST} list" SERVICES=$(grpcurl -plaintext ${GRPC_HOST} list 2>&1) echo "$SERVICES" if echo "$SERVICES" | grep -q "svrnty.cqrs.events.EventService"; then echo -e "${GREEN}✓ Test 1 passed: EventService found${NC}" else echo -e "❌ Test 1 failed: EventService not found" fi echo "" # Test 2: Describe EventService echo -e "${YELLOW}Test 2: Describe EventService${NC}" echo "grpcurl -plaintext ${GRPC_HOST} describe svrnty.cqrs.events.EventService" DESCRIBE=$(grpcurl -plaintext ${GRPC_HOST} describe svrnty.cqrs.events.EventService 2>&1) echo "$DESCRIBE" if echo "$DESCRIBE" | grep -q "Subscribe"; then echo -e "${GREEN}✓ Test 2 passed: Subscribe method found${NC}" else echo -e "❌ Test 2 failed: Subscribe method not found" fi echo "" # Test 3: Execute gRPC Command echo -e "${YELLOW}Test 3: Execute AddUser via gRPC CommandService${NC}" echo "grpcurl -plaintext -d '{...}' ${GRPC_HOST} cqrs.CommandService.AddUser" COMMAND_RESPONSE=$(grpcurl -plaintext -d '{ "name": "gRPC User", "email": "grpc-user@example.com", "age": 25 }' ${GRPC_HOST} cqrs.CommandService.AddUser 2>&1) echo "$COMMAND_RESPONSE" if echo "$COMMAND_RESPONSE" | grep -q "result"; then echo -e "${GREEN}✓ Test 3 passed: Command executed successfully${NC}" else echo -e "❌ Test 3 failed: Command execution failed" fi echo "" # Test 4: gRPC Query echo -e "${YELLOW}Test 4: Execute Query via gRPC QueryService${NC}" echo "grpcurl -plaintext -d '{...}' ${GRPC_HOST} cqrs.QueryService.FetchUser" QUERY_RESPONSE=$(grpcurl -plaintext -d '{ "userId": 1234 }' ${GRPC_HOST} cqrs.QueryService.FetchUser 2>&1) echo "$QUERY_RESPONSE" if echo "$QUERY_RESPONSE" | grep -q "userId"; then echo -e "${GREEN}✓ Test 4 passed: Query executed successfully${NC}" else echo -e "❌ Test 4 failed: Query execution failed" fi echo "" # Test 5: EventService Subscription (Manual Test) echo -e "${YELLOW}Test 5: EventService Subscription${NC}" echo -e "${BLUE}This test requires manual verification:${NC}" echo "" echo "1. Open a new terminal window" echo "2. Run the following command to start a gRPC event subscription:" echo "" echo -e "${GREEN}grpcurl -plaintext -d @ ${GRPC_HOST} svrnty.cqrs.events.EventService.Subscribe <