Skip to content

Test

Test #6

Workflow file for this run

name: Test
on:
workflow_dispatch:
inputs:
run_integration_tests:
description: 'Run integration tests (requires AWS credentials)'
required: false
default: 'false'
type: choice
options:
- 'false'
- 'true'
schedule:
- cron: '0 6 * * 1' # Weekly on Mondays at 6 AM UTC
jobs:
terratest-examples:
name: Terratest Examples
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch' || github.event_name == 'schedule'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.9.0
- name: Run Example Tests
run: |
cd test
go test -v -timeout 10m -run TestExamples
env:
TF_IN_AUTOMATION: true
terratest-integration:
name: Terratest Integration
runs-on: ubuntu-latest
if: github.event.inputs.run_integration_tests == 'true' || github.event_name == 'schedule'
strategy:
matrix:
test: [
'TestBasicBackupPlan',
'TestIAMRoleCreation'
]
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.9.0
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Run Integration Test - ${{ matrix.test }}
run: |
cd test
go test -v -timeout 30m -run ${{ matrix.test }}
env:
TF_IN_AUTOMATION: true
AWS_DEFAULT_REGION: us-east-1
TEST_UNIQUE_SUFFIX: ${{ github.run_id }}-${{ matrix.test }}
terratest-integration-advanced:
name: Terratest Integration Advanced
runs-on: ubuntu-latest
if: github.event.inputs.run_integration_tests == 'true' && github.event_name == 'schedule'
strategy:
matrix:
test: [
'TestMultipleBackupPlans',
'TestBackupPlanWithNotifications',
'TestCrossRegionBackup',
'TestBackupRestore'
]
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.9.0
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Run Advanced Integration Test - ${{ matrix.test }}
run: |
cd test
# Set appropriate timeout based on test type
TIMEOUT="45m"
if [[ "${{ matrix.test }}" == "TestCrossRegionBackup" ]]; then
TIMEOUT="60m"
elif [[ "${{ matrix.test }}" == "TestBackupRestore" ]]; then
TIMEOUT="120m" # 2 hours for backup/restore cycle
fi
go test -v -timeout $TIMEOUT -run ${{ matrix.test }}
env:
TF_IN_AUTOMATION: true
AWS_DEFAULT_REGION: us-east-1
TEST_UNIQUE_SUFFIX: ${{ github.run_id }}-${{ matrix.test }}
test-summary:
name: Test Summary
runs-on: ubuntu-latest
needs: [terratest-examples, terratest-integration, terratest-integration-advanced]
if: always()
steps:
- name: Test Results
run: |
echo "## Test Summary" >> $GITHUB_STEP_SUMMARY
echo "| Test Suite | Status |" >> $GITHUB_STEP_SUMMARY
echo "|------------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Examples | ${{ needs.terratest-examples.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Integration | ${{ needs.terratest-integration.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Integration Advanced | ${{ needs.terratest-integration-advanced.result }} |" >> $GITHUB_STEP_SUMMARY
if [[ "${{ needs.terratest-examples.result }}" == "failure" || "${{ needs.terratest-integration.result }}" == "failure" || "${{ needs.terratest-integration-advanced.result }}" == "failure" ]]; then
echo "❌ Some tests failed. Please check the logs for details." >> $GITHUB_STEP_SUMMARY
exit 1
else
echo "✅ All tests passed successfully!" >> $GITHUB_STEP_SUMMARY
fi