run-tests.sh 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #!/bin/bash
  2. set -e
  3. # Colors for output
  4. RED='\033[0;31m'
  5. GREEN='\033[0;32m'
  6. YELLOW='\033[1;33m'
  7. BLUE='\033[0;34m'
  8. NC='\033[0m' # No Color
  9. echo -e "${BLUE}=== SeaweedFS PostgreSQL Test Setup ===${NC}"
  10. # Function to wait for service
  11. wait_for_service() {
  12. local service=$1
  13. local max_wait=$2
  14. local count=0
  15. echo -e "${YELLOW}Waiting for $service to be ready...${NC}"
  16. while [ $count -lt $max_wait ]; do
  17. if docker-compose ps $service | grep -q "healthy\|Up"; then
  18. echo -e "${GREEN}✓ $service is ready${NC}"
  19. return 0
  20. fi
  21. sleep 2
  22. count=$((count + 1))
  23. echo -n "."
  24. done
  25. echo -e "${RED}✗ Timeout waiting for $service${NC}"
  26. return 1
  27. }
  28. # Function to show logs
  29. show_logs() {
  30. local service=$1
  31. echo -e "${BLUE}=== $service logs ===${NC}"
  32. docker-compose logs --tail=20 $service
  33. echo
  34. }
  35. # Parse command line arguments
  36. case "$1" in
  37. "start")
  38. echo -e "${YELLOW}Starting SeaweedFS cluster and PostgreSQL server...${NC}"
  39. docker-compose up -d seaweedfs postgres-server
  40. wait_for_service "seaweedfs" 30
  41. wait_for_service "postgres-server" 15
  42. echo -e "${GREEN}✓ SeaweedFS and PostgreSQL server are running${NC}"
  43. echo
  44. echo "You can now:"
  45. echo " • Run data producer: $0 produce"
  46. echo " • Run test client: $0 test"
  47. echo " • Connect with psql: $0 psql"
  48. echo " • View logs: $0 logs [service]"
  49. echo " • Stop services: $0 stop"
  50. ;;
  51. "produce")
  52. echo -e "${YELLOW}Creating MQ test data...${NC}"
  53. docker-compose up --build mq-producer
  54. if [ $? -eq 0 ]; then
  55. echo -e "${GREEN}✓ Test data created successfully${NC}"
  56. echo
  57. echo "You can now run: $0 test"
  58. else
  59. echo -e "${RED}✗ Data production failed${NC}"
  60. show_logs "mq-producer"
  61. fi
  62. ;;
  63. "test")
  64. echo -e "${YELLOW}Running PostgreSQL client tests...${NC}"
  65. docker-compose up --build postgres-client
  66. if [ $? -eq 0 ]; then
  67. echo -e "${GREEN}✓ Client tests completed${NC}"
  68. else
  69. echo -e "${RED}✗ Client tests failed${NC}"
  70. show_logs "postgres-client"
  71. fi
  72. ;;
  73. "psql")
  74. echo -e "${YELLOW}Connecting to PostgreSQL with psql...${NC}"
  75. docker-compose run --rm psql-cli psql -h postgres-server -p 5432 -U seaweedfs -d default
  76. ;;
  77. "logs")
  78. service=${2:-"seaweedfs"}
  79. show_logs "$service"
  80. ;;
  81. "status")
  82. echo -e "${BLUE}=== Service Status ===${NC}"
  83. docker-compose ps
  84. ;;
  85. "stop")
  86. echo -e "${YELLOW}Stopping all services...${NC}"
  87. docker-compose down
  88. echo -e "${GREEN}✓ All services stopped${NC}"
  89. ;;
  90. "clean")
  91. echo -e "${YELLOW}Cleaning up everything (including data)...${NC}"
  92. docker-compose down -v
  93. docker system prune -f
  94. echo -e "${GREEN}✓ Cleanup completed${NC}"
  95. ;;
  96. "all")
  97. echo -e "${YELLOW}Running complete test suite...${NC}"
  98. # Start services (wait_for_service ensures they're ready)
  99. $0 start
  100. # Create data (docker-compose up is synchronous)
  101. $0 produce
  102. # Run tests
  103. $0 test
  104. echo -e "${GREEN}✓ Complete test suite finished${NC}"
  105. ;;
  106. *)
  107. echo "Usage: $0 {start|produce|test|psql|logs|status|stop|clean|all}"
  108. echo
  109. echo "Commands:"
  110. echo " start - Start SeaweedFS and PostgreSQL server"
  111. echo " produce - Create MQ test data (run after start)"
  112. echo " test - Run PostgreSQL client tests (run after produce)"
  113. echo " psql - Connect with psql CLI"
  114. echo " logs - Show service logs (optionally specify service name)"
  115. echo " status - Show service status"
  116. echo " stop - Stop all services"
  117. echo " clean - Stop and remove all data"
  118. echo " all - Run complete test suite (start -> produce -> test)"
  119. echo
  120. echo "Example workflow:"
  121. echo " $0 all # Complete automated test"
  122. echo " $0 start # Manual step-by-step"
  123. echo " $0 produce"
  124. echo " $0 test"
  125. echo " $0 psql # Interactive testing"
  126. exit 1
  127. ;;
  128. esac