blob: aaec54691bec0e1fb46f4333519f29470c8a5f3b (
plain)
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
|
#!/bin/bash
# Complete Test Environment Setup Script
# This script sets up all required services and configurations for S3 IAM integration tests
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo -e "${BLUE}๐ Setting up complete test environment for SeaweedFS S3 IAM...${NC}"
echo -e "${BLUE}==========================================================${NC}"
# Check prerequisites
check_prerequisites() {
echo -e "${YELLOW}๐ Checking prerequisites...${NC}"
local missing_tools=()
for tool in docker jq curl; do
if ! command -v "$tool" >/dev/null 2>&1; then
missing_tools+=("$tool")
fi
done
if [ ${#missing_tools[@]} -gt 0 ]; then
echo -e "${RED}[FAIL] Missing required tools: ${missing_tools[*]}${NC}"
echo -e "${YELLOW}Please install the missing tools and try again${NC}"
exit 1
fi
echo -e "${GREEN}[OK] All prerequisites met${NC}"
}
# Set up Keycloak for OIDC testing
setup_keycloak() {
echo -e "\n${BLUE}1. Setting up Keycloak for OIDC testing...${NC}"
if ! "${SCRIPT_DIR}/setup_keycloak.sh"; then
echo -e "${RED}[FAIL] Failed to set up Keycloak${NC}"
return 1
fi
echo -e "${GREEN}[OK] Keycloak setup completed${NC}"
}
# Set up SeaweedFS test cluster
setup_seaweedfs_cluster() {
echo -e "\n${BLUE}2. Setting up SeaweedFS test cluster...${NC}"
# Build SeaweedFS binary if needed
echo -e "${YELLOW}๐ง Building SeaweedFS binary...${NC}"
cd "${SCRIPT_DIR}/../../../" # Go to seaweedfs root
if ! make > /dev/null 2>&1; then
echo -e "${RED}[FAIL] Failed to build SeaweedFS binary${NC}"
return 1
fi
cd "${SCRIPT_DIR}" # Return to test directory
# Clean up any existing test data
echo -e "${YELLOW}๐งน Cleaning up existing test data...${NC}"
rm -rf test-volume-data/* 2>/dev/null || true
echo -e "${GREEN}[OK] SeaweedFS cluster setup completed${NC}"
}
# Set up test data and configurations
setup_test_configurations() {
echo -e "\n${BLUE}3. Setting up test configurations...${NC}"
# Ensure IAM configuration is properly set up
if [ ! -f "${SCRIPT_DIR}/iam_config.json" ]; then
echo -e "${YELLOW}โ ๏ธ IAM configuration not found, using default config${NC}"
cp "${SCRIPT_DIR}/iam_config.local.json" "${SCRIPT_DIR}/iam_config.json" 2>/dev/null || {
echo -e "${RED}[FAIL] No IAM configuration files found${NC}"
return 1
}
fi
# Validate configuration
if ! jq . "${SCRIPT_DIR}/iam_config.json" >/dev/null; then
echo -e "${RED}[FAIL] Invalid IAM configuration JSON${NC}"
return 1
fi
echo -e "${GREEN}[OK] Test configurations set up${NC}"
}
# Verify services are ready
verify_services() {
echo -e "\n${BLUE}4. Verifying services are ready...${NC}"
# Check if Keycloak is responding
echo -e "${YELLOW}๐ Checking Keycloak availability...${NC}"
local keycloak_ready=false
for i in $(seq 1 30); do
if curl -sf "http://localhost:8080/health/ready" >/dev/null 2>&1; then
keycloak_ready=true
break
fi
if curl -sf "http://localhost:8080/realms/master" >/dev/null 2>&1; then
keycloak_ready=true
break
fi
sleep 2
done
if [ "$keycloak_ready" = true ]; then
echo -e "${GREEN}[OK] Keycloak is ready${NC}"
else
echo -e "${YELLOW}โ ๏ธ Keycloak may not be fully ready yet${NC}"
echo -e "${YELLOW}This is okay - tests will wait for Keycloak when needed${NC}"
fi
echo -e "${GREEN}[OK] Service verification completed${NC}"
}
# Set up environment variables
setup_environment() {
echo -e "\n${BLUE}5. Setting up environment variables...${NC}"
export ENABLE_DISTRIBUTED_TESTS=true
export ENABLE_PERFORMANCE_TESTS=true
export ENABLE_STRESS_TESTS=true
export KEYCLOAK_URL="http://localhost:8080"
export S3_ENDPOINT="http://localhost:8333"
export TEST_TIMEOUT=60m
export CGO_ENABLED=0
# Write environment to a file for other scripts to source
cat > "${SCRIPT_DIR}/.test_env" << EOF
export ENABLE_DISTRIBUTED_TESTS=true
export ENABLE_PERFORMANCE_TESTS=true
export ENABLE_STRESS_TESTS=true
export KEYCLOAK_URL="http://localhost:8080"
export S3_ENDPOINT="http://localhost:8333"
export TEST_TIMEOUT=60m
export CGO_ENABLED=0
EOF
echo -e "${GREEN}[OK] Environment variables set${NC}"
}
# Display setup summary
display_summary() {
echo -e "\n${BLUE}๐ Setup Summary${NC}"
echo -e "${BLUE}=================${NC}"
echo -e "Keycloak URL: ${KEYCLOAK_URL:-http://localhost:8080}"
echo -e "S3 Endpoint: ${S3_ENDPOINT:-http://localhost:8333}"
echo -e "Test Timeout: ${TEST_TIMEOUT:-60m}"
echo -e "IAM Config: ${SCRIPT_DIR}/iam_config.json"
echo -e ""
echo -e "${GREEN}[OK] Complete test environment setup finished!${NC}"
echo -e "${YELLOW}๐ก You can now run tests with: make run-all-tests${NC}"
echo -e "${YELLOW}๐ก Or run specific tests with: go test -v -timeout=60m -run TestName${NC}"
echo -e "${YELLOW}๐ก To stop Keycloak: docker stop keycloak-iam-test${NC}"
}
# Main execution
main() {
check_prerequisites
# Track what was set up for cleanup on failure
local setup_steps=()
if setup_keycloak; then
setup_steps+=("keycloak")
else
echo -e "${RED}[FAIL] Failed to set up Keycloak${NC}"
exit 1
fi
if setup_seaweedfs_cluster; then
setup_steps+=("seaweedfs")
else
echo -e "${RED}[FAIL] Failed to set up SeaweedFS cluster${NC}"
exit 1
fi
if setup_test_configurations; then
setup_steps+=("config")
else
echo -e "${RED}[FAIL] Failed to set up test configurations${NC}"
exit 1
fi
setup_environment
verify_services
display_summary
echo -e "${GREEN}๐ All setup completed successfully!${NC}"
}
# Cleanup on script interruption
cleanup() {
echo -e "\n${YELLOW}๐งน Cleaning up on script interruption...${NC}"
# Note: We don't automatically stop Keycloak as it might be shared
echo -e "${YELLOW}๐ก If you want to stop Keycloak: docker stop keycloak-iam-test${NC}"
exit 1
}
trap cleanup INT TERM
# Execute main function
main "$@"
|