simplified-integration-test.sh
1 #!/bin/bash 2 3 # Exit on error 4 set -e 5 6 # Set colors for better output 7 GREEN="\033[0;32m" 8 BLUE="\033[0;34m" 9 YELLOW="\033[0;33m" 10 RED="\033[0;31m" 11 RESET="\033[0m" 12 13 echo -e "${BLUE}" 14 echo -e "╔════════════════════════════════════════════════════════════════╗" 15 echo -e "║ ║" 16 echo -e "║ KeepSync Integration Tests ║" 17 echo -e "║ ║" 18 echo -e "╚════════════════════════════════════════════════════════════════╝" 19 echo -e "${RESET}" 20 21 # Set directories 22 SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 23 PROJECT_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)" 24 BUILD_DIR="${PROJECT_ROOT}/bin" 25 TEST_DATA_DIR="${PROJECT_ROOT}/test-data" 26 TEST_TEMP_DIR="${TEST_DATA_DIR}/temp" 27 28 # Check if the binary exists 29 if [ ! -f "${BUILD_DIR}/keepsync" ]; then 30 echo -e "${RED}Error: Binary not found at ${BUILD_DIR}/keepsync${RESET}" 31 echo -e "${YELLOW}Please build the project first with './scripts/integrated-build.sh build'${RESET}" 32 exit 1 33 fi 34 35 # Create test directories 36 mkdir -p "${TEST_TEMP_DIR}/source" 37 mkdir -p "${TEST_TEMP_DIR}/destination" 38 mkdir -p "${TEST_TEMP_DIR}/config" 39 40 # Create test files 41 echo -e "${YELLOW}Creating test files...${RESET}" 42 dd if=/dev/urandom of="${TEST_TEMP_DIR}/source/file1.bin" bs=1M count=1 43 dd if=/dev/urandom of="${TEST_TEMP_DIR}/source/file2.bin" bs=1M count=2 44 dd if=/dev/urandom of="${TEST_TEMP_DIR}/source/file3.bin" bs=1M count=3 45 echo "This is a text file" > "${TEST_TEMP_DIR}/source/file4.txt" 46 mkdir -p "${TEST_TEMP_DIR}/source/subdir" 47 dd if=/dev/urandom of="${TEST_TEMP_DIR}/source/subdir/file5.bin" bs=1M count=1 48 echo "This is another text file" > "${TEST_TEMP_DIR}/source/subdir/file6.txt" 49 50 # Create test configuration 51 echo -e "${YELLOW}Creating test configuration...${RESET}" 52 cat > "${TEST_TEMP_DIR}/config/test-config.json" << EOF 53 { 54 "source": "${TEST_TEMP_DIR}/source", 55 "destination": "${TEST_TEMP_DIR}/destination", 56 "providers": [ 57 { 58 "name": "local", 59 "type": "local", 60 "options": { 61 "path": "${TEST_TEMP_DIR}/destination" 62 } 63 } 64 ], 65 "encryption": { 66 "enabled": true, 67 "useTpm": false, 68 "password": "test-password" 69 }, 70 "chunking": { 71 "enabled": true, 72 "chunkSize": 1048576 73 }, 74 "compression": { 75 "enabled": true, 76 "level": "adaptive" 77 }, 78 "metadata": { 79 "encryptLocally": true 80 } 81 } 82 EOF 83 84 # Run the tests 85 echo -e "${YELLOW}Running integration tests...${RESET}" 86 87 # Test 1: Basic synchronization 88 echo -e "${YELLOW}Test 1: Basic synchronization${RESET}" 89 "${BUILD_DIR}/keepsync" sync --config "${TEST_TEMP_DIR}/config/test-config.json" --verbose 90 91 # Verify files were synchronized 92 if [ ! -d "${TEST_TEMP_DIR}/destination" ]; then 93 echo -e "${RED}Test 1 failed: Destination directory not created${RESET}" 94 exit 1 95 fi 96 97 # Test 2: Verify metadata encryption 98 echo -e "${YELLOW}Test 2: Verify metadata encryption${RESET}" 99 # This is a simplified test - in a real scenario, we would check if metadata files are encrypted 100 if [ -f "${TEST_TEMP_DIR}/destination/.metadata" ]; then 101 # Check if the file contains binary data (encrypted) 102 if grep -q "^[[:print:]]*$" "${TEST_TEMP_DIR}/destination/.metadata"; then 103 echo -e "${RED}Test 2 failed: Metadata appears to be plaintext${RESET}" 104 else 105 echo -e "${GREEN}Test 2 passed: Metadata appears to be encrypted${RESET}" 106 fi 107 else 108 echo -e "${YELLOW}Test 2 skipped: No metadata file found${RESET}" 109 fi 110 111 # Test 3: Modify a file and sync again 112 echo -e "${YELLOW}Test 3: Incremental synchronization${RESET}" 113 echo "Modified content" >> "${TEST_TEMP_DIR}/source/file4.txt" 114 "${BUILD_DIR}/keepsync" sync --config "${TEST_TEMP_DIR}/config/test-config.json" --verbose 115 116 # Test 4: Delete a file and sync again 117 echo -e "${YELLOW}Test 4: Deletion synchronization${RESET}" 118 rm "${TEST_TEMP_DIR}/source/file1.bin" 119 "${BUILD_DIR}/keepsync" sync --config "${TEST_TEMP_DIR}/config/test-config.json" --verbose 120 121 # Clean up 122 echo -e "${YELLOW}Cleaning up test data...${RESET}" 123 rm -rf "${TEST_TEMP_DIR}/source" 124 rm -rf "${TEST_TEMP_DIR}/destination" 125 rm -rf "${TEST_TEMP_DIR}/config" 126 127 echo -e "${GREEN}Integration tests completed.${RESET}" 128 exit 0