#!/bin/bash echo "๐Ÿงช Testing Caddy-RS File Sync System" echo "====================================" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Test directories SERVER_DIR="./sync-data" CLIENT_DIR="./test-client-sync" echo -e "\n${YELLOW}๐Ÿ“ Checking test setup...${NC}" echo "Server directory: $SERVER_DIR" echo "Client directory: $CLIENT_DIR" echo "Files in server directory:" find $SERVER_DIR -type f | head -10 echo -e "\n${YELLOW}๐Ÿ”จ Building project...${NC}" cargo build --release if [ $? -ne 0 ]; then echo -e "${RED}โŒ Build failed${NC}" exit 1 fi echo -e "${GREEN}โœ… Build successful${NC}" echo -e "\n${YELLOW}๐Ÿš€ Starting server (background)...${NC}" cargo run --bin caddy-rs --release -- -c example-sync-config.json & SERVER_PID=$! echo "Server PID: $SERVER_PID" # Wait for server to start echo "Waiting for server to start..." sleep 3 echo -e "\n${YELLOW}๐Ÿ” Testing API endpoints...${NC}" # Test 1: List files echo "Test 1: GET /api/list" curl -s http://localhost:8080/api/list > /tmp/file_list.json if [ $? -eq 0 ]; then echo -e "${GREEN}โœ… List API works${NC}" echo "Found $(cat /tmp/file_list.json | wc -l) files" else echo -e "${RED}โŒ List API failed${NC}" fi # Test 2: Download a file echo -e "\nTest 2: GET /api/download?path=README.md" curl -s "http://localhost:8080/api/download?path=README.md" > /tmp/downloaded_readme.md if [ $? -eq 0 ] && [ -s /tmp/downloaded_readme.md ]; then echo -e "${GREEN}โœ… Download API works${NC}" echo "Downloaded $(wc -l < /tmp/downloaded_readme.md) lines" else echo -e "${RED}โŒ Download API failed${NC}" fi # Test 3: Upload a file echo -e "\nTest 3: POST /api/upload?path=test-upload.txt" echo "This is a test upload file" > /tmp/test_upload.txt curl -s -X POST "http://localhost:8080/api/upload?path=test-upload.txt" \ -H "Content-Type: application/octet-stream" \ --data-binary @/tmp/test_upload.txt if [ $? -eq 0 ]; then echo -e "${GREEN}โœ… Upload API works${NC}" # Verify file exists on server if [ -f "$SERVER_DIR/test-upload.txt" ]; then echo -e "${GREEN}โœ… File successfully created on server${NC}" else echo -e "${RED}โŒ File not found on server${NC}" fi else echo -e "${RED}โŒ Upload API failed${NC}" fi # Test 4: Metadata echo -e "\nTest 4: GET /api/metadata?path=README.md" curl -s "http://localhost:8080/api/metadata?path=README.md" > /tmp/metadata.json if [ $? -eq 0 ] && [ -s /tmp/metadata.json ]; then echo -e "${GREEN}โœ… Metadata API works${NC}" echo "Metadata: $(cat /tmp/metadata.json)" else echo -e "${RED}โŒ Metadata API failed${NC}" fi echo -e "\n${YELLOW}๐Ÿงน Cleanup...${NC}" # Kill server kill $SERVER_PID 2>/dev/null sleep 1 # Clean up temp files rm -f /tmp/file_list.json /tmp/downloaded_readme.md /tmp/test_upload.txt /tmp/metadata.json echo -e "\n${GREEN}๐ŸŽ‰ API testing complete!${NC}" echo -e "\n${YELLOW}๐Ÿ“‹ Next steps:${NC}" echo "1. Test the sync client binary" echo "2. Test bidirectional synchronization" echo "3. Test conflict resolution" echo "4. Test real-time file watching" echo -e "\n${YELLOW}๐Ÿ’ก To test sync client:${NC}" echo "cargo run --bin sync-client -- --server http://localhost:8080 --local-path ./test-client-sync --initial-sync"