Repository navigation
feat: Rename E2E provision tests to include destroy workflow with DestroyCommand integration - #15
Conversation
- Rename src/bin/e2e_provision_tests.rs to src/bin/e2e_provision_and_destroy_tests.rs - Update binary to use DestroyCommand with fallback to manual cleanup - Update Cargo.toml with new binary name - Update GitHub Actions workflow with new binary name and descriptions Co-authored-by: josecelano <[email protected]>
- Update docs/e2e-testing.md with new binary name and destroy workflow - Update docs/codebase-architecture.md binary list - Update docs/decisions/docker-testing-evolution.md with new binary name - Update docs/research/ansible-testing-strategy.md examples - Update docs/features/environment-state-management/ documentation Co-authored-by: josecelano <[email protected]>
- Add backticks to DestroyCommand in doc comment - Remove unnecessary Result return type from run_infrastructure_destroy - Run cargo fmt to format code Co-authored-by: josecelano <[email protected]>
🛠️ Fix: GitHub Actions Workflow Directory Conflict@copilot, the E2E Provision workflow is failing due to a directory conflict after the Problem AnalysisThe workflow step "Cleanup infrastructure (always run)" was failing with: Root Cause: The new Solution: Failure-Only CleanupChanged the cleanup step to only run on test failure ( ✅ Safety net for provision failures: If the test fails during provisioning (before DestroyCommand runs), we still attempt cleanup Updated Workflow Logic- name: Cleanup infrastructure (on failure only)
if: failure() # Only run when test fails
run: |
echo "Test failed - attempting emergency cleanup..."
# Try OpenTofu cleanup only if build directory still exists
if [ -d "build/e2e-provision/tofu/lxd" ]; then
echo "Found OpenTofu state directory, attempting tofu destroy..."
cd build/e2e-provision/tofu/lxd
sudo -E tofu destroy -auto-approve || echo "Tofu destroy failed or nothing to destroy"
else
echo "No OpenTofu state directory found (likely cleaned up by DestroyCommand)"
fi
# Always attempt LXD cleanup (no working directory dependency)
echo "Attempting LXD resource cleanup..."
sudo lxc delete torrust-tracker-vm-e2e-provision --force || echo "Container deletion failed or container doesn't exist"
sudo lxc profile delete torrust-profile-e2e-provision || echo "Profile deletion failed or profile doesn't exist"This maintains the "better to double-fail than leave resources" philosophy while avoiding the directory conflict when tests succeed and DestroyCommand properly cleans up. |
…ry existence - Change cleanup step from 'if: always()' to 'if: failure()' to avoid conflicts when DestroyCommand succeeds - Add directory existence checks before attempting to cd into build directories - Update 'Get test outputs' step to handle missing build directory gracefully - Update 'Debug information' step to check if directory exists before accessing it - Maintain emergency cleanup capability for provision and DestroyCommand failures - Remove working-directory dependency from cleanup step to prevent errors Co-authored-by: josecelano <[email protected]>
Fixed in commit 31e8c61. The workflow cleanup step now:
The "Get test outputs" and "Debug information" steps also now check for directory existence before attempting to access the build directory. |
|
ACK bd76a84 |
- Add rule #15 to Essential Rules section in AGENTS.md - Emphasizes CRITICAL importance of using it_should_* pattern - Explicitly forbids test_* prefix for test function names - References docs/contributing/testing/unit-testing.md for details - Includes examples of correct vs incorrect naming - Preventive measure to avoid future test naming violations
src/bin/e2e_provision_tests.rstosrc/bin/e2e_provision_and_destroy_tests.rsCargo.tomlfrome2e-provision-teststoe2e-provision-and-destroy-testsrun_destroy_commandinstead ofcleanup_test_infrastructurecleanup_test_infrastructure) on destroy command failure.github/workflows/test-e2e-provision.yml) with new binary namedocs/e2e-testing.md) with new binary name and functionalitySummary
Successfully renamed and updated the E2E provision tests binary to include destroy functionality:
Key Changes
Binary Renamed:
e2e-provision-tests→e2e-provision-and-destroy-testsCargo.tomlwith new binary namee2e_provision_tests.rstoe2e_provision_and_destroy_tests.rsDestroyCommand Integration:
run_destroy_commandfrom application layercleanup_test_infrastructureon destroy command failuresDocumentation Updates:
docs/e2e-testing.mdwith new binary name and destroy workflowdocs/codebase-architecture.mdbinary listdocs/decisions/docker-testing-evolution.mddocs/research/ansible-testing-strategy.mdexamplesdocs/features/environment-state-management/documentationCI/CD Updates:
.github/workflows/test-e2e-provision.ymlwith new binary nameGitHub Actions Workflow Fix
Fixed directory conflict where the cleanup step was failing because
DestroyCommandsuccessfully removes thebuild/directory:if: always()toif: failure()- only runs when tests failTesting
Verification
The binary now provides complete lifecycle testing:
DestroyCommand(with fallback)This ensures comprehensive E2E testing of the full provision+destroy lifecycle while maintaining reliable cleanup in CI environments.
Original prompt
This section details on the original issue you should resolve
<issue_title>Rename and Update E2E Provision Tests to Include Destroy</issue_title>
<issue_description># Rename and Update E2E Provision Tests to Include Destroy
Issue Type: Sub-issue (9.2)
Parent Epic: #9 (
epic-app-layer-destroy-command.md)Related Roadmap: Section 1.2
Dependencies: Issue #11 (Add DestroyCommand in Application Layer) must be completed first
Priority: High
Estimated Effort: 3-4 hours
📋 Issue Overview
Modify and rename
src/bin/e2e_provision_tests.rstosrc/bin/e2e_provision_and_destroy_tests.rs, updating it to use the new destroy command instead of manual cleanup, ensuring CI can run complete provision+destroy cycles.This ensures we have automated testing of the destroy functionality in CI, preventing regressions. The provision tests are already running real OpenTofu infrastructure, so adding destroy testing here gives us confidence the feature works end-to-end.
🎯 Goals
DestroyCommandin E2E provision tests📦 Scope
Core Changes
e2e_provision_tests.rstoe2e_provision_and_destroy_tests.rsDestroyCommandIntegration Points
🏗️ Technical Design
Test Flow Integration
Current flow:
New flow:
Error Handling Strategy
Binary Renaming
Rename
e2e_provision_tests.rstoe2e_provision_and_destroy_tests.rsto reflect the expanded functionality:📋 Acceptance Criteria
e2e_provision_tests.rstoe2e_provision_and_destroy_tests.rsDestroyCommandfor cleanup instead of manual cleanup🧪 Testing Strategy
Local Testing
CI Testing
Error Scenarios
🔗 Dependencies
📝 Implementation Notes
Current E2E Provision Test Structure
The current
src/bin/e2e_provision_tests.rsbinary:After this issue, the renamed
src/bin/e2e_provision_and_destroy_tests.rsbinary will:DestroyCommand(with manual cleanup fallback)Integration Approach
e2e_provision_tests.rsto `e2e_provision_and_...Fixes #12
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.