-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-testing.sh
More file actions
executable file
Β·233 lines (191 loc) Β· 6.46 KB
/
setup-testing.sh
File metadata and controls
executable file
Β·233 lines (191 loc) Β· 6.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#!/bin/bash
# FlexFit Testing Environment Setup
# Makes all test scripts executable and installs dependencies
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
echo -e "${BLUE}π§ FlexFit Testing Environment Setup${NC}"
echo "===================================="
# Function to check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Function to install missing dependencies
install_dependencies() {
echo -e "\n${YELLOW}π¦ Checking dependencies...${NC}"
local missing_deps=()
# Check required tools
if ! command_exists docker; then
missing_deps+=("docker")
else
echo "β
Docker: $(docker --version)"
fi
if ! command_exists "docker compose" && ! command_exists docker-compose; then
missing_deps+=("docker-compose")
else
if command_exists "docker compose"; then
echo "β
Docker Compose: $(docker compose version)"
else
echo "β
Docker Compose: $(docker-compose --version)"
fi
fi
if ! command_exists java; then
missing_deps+=("java")
else
echo "β
Java: $(java -version 2>&1 | head -n1)"
fi
if ! command_exists mvn; then
missing_deps+=("maven")
else
echo "β
Maven: $(mvn --version | head -n1)"
fi
if ! command_exists python3; then
missing_deps+=("python3")
else
echo "β
Python: $(python3 --version)"
fi
if ! command_exists jq; then
missing_deps+=("jq")
else
echo "β
jq: $(jq --version)"
fi
# Report missing dependencies
if [ ${#missing_deps[@]} -gt 0 ]; then
echo -e "\n${RED}β Missing dependencies:${NC}"
for dep in "${missing_deps[@]}"; do
echo -e " - ${RED}$dep${NC}"
done
echo -e "\n${YELLOW}π‘ Installation instructions:${NC}"
echo "Ubuntu/Debian:"
echo " sudo apt-get update"
echo " sudo apt-get install -y docker.io docker-compose openjdk-17-jdk maven python3 python3-pip jq"
echo ""
echo "macOS:"
echo " brew install docker docker-compose openjdk@17 maven python3 jq"
echo ""
echo "Please install missing dependencies and run this script again."
exit 1
fi
echo -e "${GREEN}β
All system dependencies are installed${NC}"
}
# Function to install Python dependencies
install_python_deps() {
echo -e "\n${YELLOW}π Installing Python test dependencies...${NC}"
local python_deps=("pytest" "pytest-cov" "requests" "fastapi" "httpx")
for dep in "${python_deps[@]}"; do
if python3 -c "import $dep" 2>/dev/null; then
echo "β
$dep already installed"
else
echo "π¦ Installing $dep..."
pip3 install "$dep" --user
fi
done
# Install GenAI worker dependencies if requirements.txt exists
if [ -f "genai/requirements.txt" ]; then
echo "π¦ Installing GenAI worker dependencies..."
pip3 install -r genai/requirements.txt --user
fi
echo -e "${GREEN}β
Python dependencies installed${NC}"
}
# Function to make scripts executable
make_scripts_executable() {
echo -e "\n${YELLOW}π¨ Making test scripts executable...${NC}"
local scripts=(
"run-all-tests.sh"
"run-unit-tests.sh"
"run-integration-tests.sh"
"test-endpoints.sh"
"setup-testing.sh"
)
for script in "${scripts[@]}"; do
if [ -f "$script" ]; then
chmod +x "$script"
echo "β
Made $script executable"
else
echo "β οΈ $script not found"
fi
done
echo -e "${GREEN}β
Test scripts are now executable${NC}"
}
# Function to create test directories
create_test_directories() {
echo -e "\n${YELLOW}π Creating test directories...${NC}"
mkdir -p test-reports
mkdir -p test-data
echo "β
Created test-reports directory"
echo "β
Created test-data directory"
echo -e "${GREEN}β
Test directories created${NC}"
}
# Function to verify setup
verify_setup() {
echo -e "\n${YELLOW}π Verifying setup...${NC}"
# Check if Docker is running
if docker info >/dev/null 2>&1; then
echo "β
Docker daemon is running"
else
echo -e "${YELLOW}β οΈ Docker daemon is not running. Please start Docker.${NC}"
fi
# Check if test scripts are executable
local executable_count=0
for script in run-all-tests.sh run-unit-tests.sh run-integration-tests.sh; do
if [ -x "$script" ]; then
executable_count=$((executable_count + 1))
fi
done
echo "β
$executable_count test scripts are executable"
# Check Python test dependencies
if python3 -c "import pytest" 2>/dev/null; then
echo "β
Python testing framework is ready"
else
echo "β Python testing framework setup failed"
fi
echo -e "${GREEN}β
Setup verification complete${NC}"
}
# Function to show usage examples
show_usage_examples() {
echo -e "\n${BLUE}π Usage Examples${NC}"
echo "=================="
echo ""
echo "Run all tests:"
echo -e " ${GREEN}./run-all-tests.sh${NC}"
echo ""
echo "Run only unit tests:"
echo -e " ${GREEN}./run-unit-tests.sh${NC}"
echo ""
echo "Run only integration tests:"
echo -e " ${GREEN}./run-integration-tests.sh${NC}"
echo ""
echo "Run all tests with coverage and reports:"
echo -e " ${GREEN}./run-all-tests.sh -a -c -r${NC}"
echo ""
echo "Manual API endpoint testing:"
echo -e " ${GREEN}./test-endpoints.sh${NC}"
echo ""
echo "Clean environment and run all tests:"
echo -e " ${GREEN}./run-all-tests.sh --clean -a${NC}"
echo ""
echo -e "For more options, run: ${GREEN}./run-all-tests.sh --help${NC}"
}
# Main execution
main() {
install_dependencies
install_python_deps
make_scripts_executable
create_test_directories
verify_setup
echo -e "\n${GREEN}π Testing environment setup complete!${NC}"
show_usage_examples
echo -e "\n${BLUE}π‘ Next Steps:${NC}"
echo "1. Start your services: docker compose up -d"
echo "2. Run tests: ./run-all-tests.sh"
echo "3. Check test reports in: test-reports/"
echo -e "\n${GREEN}Happy testing! π${NC}"
}
# Check if running as script or sourced
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
main "$@"
fi