-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathdev-test.sh
More file actions
executable file
·200 lines (157 loc) · 5.57 KB
/
Copy pathdev-test.sh
File metadata and controls
executable file
·200 lines (157 loc) · 5.57 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
#!/usr/bin/env bash
set -eu -o pipefail
# Developer-friendly test runner for quickstarters
# This script provides a simple interface to run quickstarter tests
# with automatic environment detection and helpful output
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ODS_CORE_DIR="${SCRIPT_DIR}/.."
# Default values
QUICKSTARTER="${1:-be-python-flask}"
PROJECT="${2:-devtest}"
PARALLEL="${3:-1}"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
function print_header() {
echo -e "\n${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BLUE} $1${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}\n"
}
function print_info() {
echo -e "${BLUE}ℹ️ $1${NC}"
}
function print_success() {
echo -e "${GREEN}✓ $1${NC}"
}
function print_warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
function print_error() {
echo -e "${RED}✗ $1${NC}"
}
function check_prerequisites() {
local missing_tools=()
# Check for required tools
if ! command -v oc &> /dev/null; then
missing_tools+=("oc (OpenShift CLI)")
fi
if ! command -v go &> /dev/null; then
missing_tools+=("go")
fi
if ! command -v jq &> /dev/null; then
missing_tools+=("jq")
fi
if [ ${#missing_tools[@]} -ne 0 ]; then
print_error "Missing required tools:"
for tool in "${missing_tools[@]}"; do
echo " - $tool"
done
echo ""
echo "Please install the missing tools and try again."
exit 1
fi
# Check if logged into OpenShift
if ! oc whoami &> /dev/null; then
print_error "Not logged into OpenShift"
echo "Please run 'oc login' first."
exit 1
fi
print_success "All prerequisites met"
}
function detect_environment() {
print_header "Environment Detection"
# Check if running in cluster
if [ -n "${KUBERNETES_SERVICE_HOST:-}" ]; then
print_info "Execution environment: Inside Kubernetes/OpenShift cluster"
print_info "Network strategy: Service DNS (no port-forwards needed)"
else
print_info "Execution environment: Local development machine"
print_info "Network strategy: Automatic (routes > port-forward > service DNS)"
print_warning "Port-forwards will be set up automatically as needed"
fi
# Show current OpenShift context
current_user=$(oc whoami 2>/dev/null || echo "unknown")
current_server=$(oc whoami --show-server 2>/dev/null || echo "unknown")
print_info "OpenShift user: $current_user"
print_info "OpenShift server: $current_server"
}
function show_test_info() {
print_header "Test Configuration"
echo " Quickstarter: $QUICKSTARTER"
echo " Project: $PROJECT"
echo " Parallelism: $PARALLEL"
echo ""
}
function run_tests() {
print_header "Running Tests"
cd "$ODS_CORE_DIR/tests"
# Run the quickstarter test
print_info "Executing: make test-quickstarter QS=$QUICKSTARTER PROJECT=$PROJECT PARALLEL=$PARALLEL"
echo ""
if make test-quickstarter QS="$QUICKSTARTER" PROJECT="$PROJECT" PARALLEL="$PARALLEL"; then
print_success "Tests passed!"
return 0
else
print_error "Tests failed!"
return 1
fi
}
function show_usage() {
cat << EOF
Usage: $0 [QUICKSTARTER] [PROJECT] [PARALLEL]
Developer-friendly test runner for ODS quickstarters.
Arguments:
QUICKSTARTER Quickstarter to test (default: be-python-flask)
Examples:
- be-python-flask (single quickstarter)
- ods-quickstarters/... (all quickstarters)
- be-golang-plain (another single quickstarter)
PROJECT OpenShift project name for testing (default: devtest)
PARALLEL Number of tests to run in parallel (default: 1)
Examples:
# Test be-python-flask in 'devtest' project
$0
# Test specific quickstarter in custom project
$0 be-golang-plain myproject
# Test all quickstarters with parallelism
$0 ods-quickstarters/... testproj 3
Features:
✓ Automatic environment detection (in-cluster vs local)
✓ Smart URL resolution (routes > port-forward > service DNS)
✓ Automatic port-forward setup for local development
✓ Automatic cleanup on exit or interrupt (Ctrl+C)
✓ Clear, colorful output
Network Access:
When running locally, the test framework will automatically:
1. Try to use OpenShift routes if they exist (fastest, most reliable)
2. Set up port-forwards for services without routes
3. Fall back to service DNS if running inside the cluster
You don't need to manually set up port-forwards - it's all automatic!
EOF
}
# Main execution
main() {
# Show usage if help requested
if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
show_usage
exit 0
fi
print_header "ODS Quickstarter Test Runner"
check_prerequisites
detect_environment
show_test_info
if run_tests; then
print_header "Test Summary"
print_success "All tests completed successfully!"
echo ""
exit 0
else
print_header "Test Summary"
print_error "Some tests failed. Check the output above for details."
exit 1
fi
}
main "$@"