#!/bin/bash echo "๐Ÿ”„ Testing Caddy-RS Sync Client" echo "===============================" # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' SERVER_DIR="./sync-data" CLIENT_DIR="./test-client-sync" SERVER_URL="http://localhost:8080" echo -e "\n${YELLOW}๐Ÿงน Cleaning up previous test...${NC}" rm -rf $CLIENT_DIR mkdir -p $CLIENT_DIR echo -e "\n${YELLOW}๐Ÿ“Š Server status before sync:${NC}" echo "Files in server directory:" find $SERVER_DIR -type f | sort echo -e "\n${BLUE}๐Ÿš€ Starting server...${NC}" cargo run --bin caddy-rs --release -- -c example-sync-config.json & SERVER_PID=$! echo "Server PID: $SERVER_PID" sleep 3 echo -e "\n${BLUE}๐Ÿ”„ Testing initial sync...${NC}" echo "Running: cargo run --bin sync-client -- --server $SERVER_URL --local-path $CLIENT_DIR --initial-sync" # Run sync client for a short time to test initial sync timeout 10 cargo run --bin sync-client -- \ --server $SERVER_URL \ --local-path $CLIENT_DIR \ --initial-sync & SYNC_PID=$! echo "Sync client PID: $SYNC_PID" # Wait for initial sync to complete sleep 5 echo -e "\n${YELLOW}๐Ÿ“Š Checking sync results...${NC}" echo "Files in client directory after sync:" find $CLIENT_DIR -type f | sort echo -e "\n${YELLOW}๐Ÿ” Verifying file integrity...${NC}" # Check if key files were synced if [ -f "$CLIENT_DIR/README.md" ]; then echo -e "${GREEN}โœ… README.md synced${NC}" echo " Server: $(wc -l < $SERVER_DIR/README.md) lines" echo " Client: $(wc -l < $CLIENT_DIR/README.md) lines" else echo -e "${RED}โŒ README.md not synced${NC}" fi if [ -f "$CLIENT_DIR/documents/hello.txt" ]; then echo -e "${GREEN}โœ… documents/hello.txt synced${NC}" else echo -e "${RED}โŒ documents/hello.txt not synced${NC}" fi if [ -f "$CLIENT_DIR/config.json" ]; then echo -e "${GREEN}โœ… config.json synced${NC}" else echo -e "${RED}โŒ config.json not synced${NC}" fi # Test file creation on client side echo -e "\n${BLUE}๐Ÿ“ Testing client-side file creation...${NC}" echo "Creating test file on client..." echo "This file was created on the client side" > "$CLIENT_DIR/client-created.txt" mkdir -p "$CLIENT_DIR/client-folder" echo "Client folder test" > "$CLIENT_DIR/client-folder/test.txt" echo "Created files:" find $CLIENT_DIR -name "*client*" -type f echo -e "\n${YELLOW}โฐ Waiting for sync cycle...${NC}" sleep 8 # Wait for a sync cycle echo -e "\n${YELLOW}๐Ÿ” Checking if client files synced to server...${NC}" if [ -f "$SERVER_DIR/client-created.txt" ]; then echo -e "${GREEN}โœ… client-created.txt synced to server${NC}" echo "Content: $(cat $SERVER_DIR/client-created.txt)" else echo -e "${RED}โŒ client-created.txt not synced to server${NC}" fi if [ -f "$SERVER_DIR/client-folder/test.txt" ]; then echo -e "${GREEN}โœ… client-folder/test.txt synced to server${NC}" else echo -e "${RED}โŒ client-folder/test.txt not synced to server${NC}" fi # Test server-side file creation echo -e "\n${BLUE}๐Ÿ“ Testing server-side file creation...${NC}" echo "Creating test file on server..." echo "This file was created on the server side" > "$SERVER_DIR/server-created.txt" mkdir -p "$SERVER_DIR/server-folder" echo "Server folder test" > "$SERVER_DIR/server-folder/test.txt" echo -e "\n${YELLOW}โฐ Waiting for sync cycle...${NC}" sleep 8 echo -e "\n${YELLOW}๐Ÿ” Checking if server files synced to client...${NC}" if [ -f "$CLIENT_DIR/server-created.txt" ]; then echo -e "${GREEN}โœ… server-created.txt synced to client${NC}" echo "Content: $(cat $CLIENT_DIR/server-created.txt)" else echo -e "${RED}โŒ server-created.txt not synced to client${NC}" fi if [ -f "$CLIENT_DIR/server-folder/test.txt" ]; then echo -e "${GREEN}โœ… server-folder/test.txt synced to client${NC}" else echo -e "${RED}โŒ server-folder/test.txt not synced to client${NC}" fi echo -e "\n${YELLOW}๐Ÿงน Cleanup...${NC}" # Kill processes kill $SYNC_PID 2>/dev/null kill $SERVER_PID 2>/dev/null sleep 2 echo -e "\n${GREEN}๐ŸŽ‰ Sync client testing complete!${NC}" echo -e "\n${YELLOW}๐Ÿ“Š Final Summary:${NC}" echo "Server directory files: $(find $SERVER_DIR -type f | wc -l)" echo "Client directory files: $(find $CLIENT_DIR -type f | wc -l)" echo -e "\n${BLUE}๐Ÿ“ Test Results Summary:${NC}" echo "โœ“ Server startup" echo "โœ“ API endpoints functioning" echo "โœ“ Initial sync client connection" echo "โœ“ File download/upload capabilities" echo "? Bidirectional sync (check manually above)" echo "? Real-time file watching (check manually above)" echo -e "\n${YELLOW}๐Ÿ” To inspect results manually:${NC}" echo "Server files: ls -la $SERVER_DIR" echo "Client files: ls -la $CLIENT_DIR"