|
295 | 295 | # Verify WP-CLI works without fatal errors |
296 | 296 | ddev exec wp core version 2>/dev/null || echo "WP-CLI not available or WordPress not fully configured" |
297 | 297 | } |
| 298 | + |
| 299 | +@test "db-refresh error handling and exit status" { |
| 300 | + set -eu -o pipefail |
| 301 | + cd $TESTDIR |
| 302 | + ddev config --project-name=$PROJNAME --project-type=wordpress --docroot=web --create-docroot |
| 303 | + ddev add-on get $DIR |
| 304 | + ddev start |
| 305 | + |
| 306 | + # Test 1: Verify db-refresh fails properly when SSH connection fails |
| 307 | + # Configure for a provider that will fail SSH connectivity test |
| 308 | + ddev config --web-environment-add="HOSTING_PROVIDER=wpengine" |
| 309 | + ddev config --web-environment-add="HOSTING_SITE=nonexistent-site-12345" |
| 310 | + ddev restart |
| 311 | + |
| 312 | + # Run db-refresh and expect it to fail with non-zero exit code |
| 313 | + # This should fail because SSH connection to nonexistent site will fail |
| 314 | + run ddev db-refresh |
| 315 | + [ "$status" -ne 0 ] || (echo "db-refresh should fail with non-zero exit code when SSH fails" && exit 1) |
| 316 | + |
| 317 | + # Test 2: Verify error message is displayed (not silenced) |
| 318 | + echo "$output" | grep -i "error" || echo "Warning: Expected error message in output" |
| 319 | + |
| 320 | + # Test 3: Test Kinsta provider with invalid SSH configuration |
| 321 | + ddev config --web-environment-add="HOSTING_PROVIDER=kinsta" |
| 322 | + ddev config --web-environment-add="REMOTE_HOST=invalid.host.example.com" |
| 323 | + ddev config --web-environment-add="REMOTE_PORT=22" |
| 324 | + ddev config --web-environment-add="REMOTE_USER=testuser" |
| 325 | + ddev config --web-environment-add="REMOTE_PATH=/invalid/path" |
| 326 | + ddev restart |
| 327 | + |
| 328 | + # This should also fail with non-zero exit code |
| 329 | + run ddev db-refresh |
| 330 | + [ "$status" -ne 0 ] || (echo "db-refresh should fail for Kinsta with invalid config" && exit 1) |
| 331 | + |
| 332 | + # Test 4: Verify refresh script itself validates properly |
| 333 | + # Check that the refresh scripts exist and have proper error handling |
| 334 | + ddev exec "test -f .ddev/scripts/refresh-wpengine.sh" || (echo "WPEngine refresh script missing" && exit 1) |
| 335 | + ddev exec "test -f .ddev/scripts/refresh-kinsta.sh" || (echo "Kinsta refresh script missing" && exit 1) |
| 336 | + ddev exec "test -f .ddev/scripts/refresh-pantheon.sh" || (echo "Pantheon refresh script missing" && exit 1) |
| 337 | + |
| 338 | + # Test 5: Verify SSH command doesn't use BatchMode (which blocks password prompts) |
| 339 | + ddev exec "grep -v 'BatchMode=yes' .ddev/scripts/refresh-wpengine.sh" || (echo "WPEngine script should not use BatchMode=yes" && exit 1) |
| 340 | + ddev exec "grep -v 'BatchMode=yes' .ddev/scripts/refresh-kinsta.sh" || (echo "Kinsta script should not use BatchMode=yes" && exit 1) |
| 341 | + |
| 342 | + # Test 6: Verify error messages are not silenced (no 2>/dev/null on SSH tests) |
| 343 | + # Check WPEngine SSH test line doesn't silence errors |
| 344 | + ddev exec "grep 'SSH connection successful' .ddev/scripts/refresh-wpengine.sh | grep -v '2>/dev/null'" || (echo "WPEngine SSH test should not silence errors" && exit 1) |
| 345 | + ddev exec "grep 'SSH connection successful' .ddev/scripts/refresh-kinsta.sh | grep -v '2>/dev/null'" || (echo "Kinsta SSH test should not silence errors" && exit 1) |
| 346 | +} |
0 commit comments