Testing and Validation Strategy
Overview¶
This document defines the comprehensive testing and validation strategy for F5 XC User and Group Sync tool, covering unit testing, integration testing, and end-to-end testing approaches. The strategy ensures code quality, reliability, and production readiness through systematic validation at multiple levels with a target code coverage of ≥90%.
Unit Testing Strategy¶
Objective: Verify individual components function correctly in isolation
Scope: All modules insrc/xc_user_group_sync/
Coverage Target: ≥90% code coverage
Key Test Areas:
- CSV Parsing (
test_csv_parser.py) - Valid CSV with required columns
- Missing required columns
- Malformed CSV data
- Empty CSV file
-
Large CSV files (performance)
-
LDAP DN Extraction (
test_ldap_utils.py) - Valid LDAP DNs with single CN
- DNs with multiple CNs (extract first)
- DNs with special characters (escaped)
- Malformed DNs (error handling)
-
DNs with Unicode characters
-
Group Name Validation (
test_validation.py) - Valid group names (alphanumeric, hyphen, underscore)
- Invalid characters (spaces, special chars)
- Length validation (1-128 characters)
- Empty strings
-
Unicode handling
-
Configuration Loading (
test_config.py) - Hierarchical .env file loading
- Environment variable precedence
- Custom DOTENV_PATH
- Missing configuration
-
Invalid configuration values
-
Retry Logic (
test_retry.py) - Exponential backoff calculation
- Retriable vs non-retriable errors
- Max attempts enforcement
- Backoff min/max bounds
Testing Framework: pytest with coverage plugin
Example Test:
def test_extract_cn_valid_dn():
"""Test CN extraction from valid LDAP DN"""
dn = "CN=Admins,OU=Groups,DC=example,DC=com"
result = extract_cn(dn)
assert result == "Admins"
def test_extract_cn_multiple_cns():
"""Test CN extraction when multiple CNs present"""
dn = "CN=Users,CN=Admins,OU=Groups,DC=example,DC=com"
result = extract_cn(dn)
assert result == "Users" # Should extract first CN
def test_extract_cn_malformed_dn():
"""Test error handling for malformed DN"""
dn = "OU=Groups,DC=example,DC=com" # Missing CN
with pytest.raises(ValueError, match="No CN component"):
extract_cn(dn)
Running Unit Tests:
# Run all unit tests with coverage
pytest tests/unit/ --cov=src/xc_user_group_sync --cov-report=html
# Run specific test file
pytest tests/unit/test_ldap_utils.py -v
# Run tests matching pattern
pytest -k "test_extract_cn" -v
Integration Testing Strategy¶
Objective: Verify components work together correctly with mocked external services
Scope: End-to-end workflows with mocked F5 XC API
Key Test Scenarios:
- Complete Sync Workflow
- Parse CSV → Aggregate groups → Sync to mock API → Verify results
- Test create, update, and unchanged operations
-
Verify operation counters accuracy
-
Authentication Methods
- Test P12 authentication flow
- Test PEM certificate authentication
- Test API token authentication
-
Test authentication failure handling
-
Retry Mechanism
- Mock transient failures (connection timeout, HTTP 503)
- Verify retry attempts occur
- Verify exponential backoff timing
-
Verify eventual success after retries
-
Error Handling
- Mock permanent failures (HTTP 401, 404, 400)
- Verify no retry occurs
- Verify error reporting
-
Verify partial failure handling
-
Dry-Run Mode
- Verify no API calls made
- Verify planned operations displayed
- Verify operation counts accurate
Testing Framework: pytest with requests-mock
Example Integration Test:
@pytest.fixture
def mock_xc_api(requests_mock):
"""Mock F5 XC API responses"""
requests_mock.get(
"https://tenant.console.ves.volterra.io/api/web/namespaces/system/user_groups",
json={"items": [{"name": "existing-group", "users": ["user1@example.com"]}]}
)
requests_mock.post(
"https://tenant.console.ves.volterra.io/api/web/namespaces/system/user_groups",
status_code=201
)
return requests_mock
def test_complete_sync_workflow(mock_xc_api, tmp_path):
"""Test complete sync workflow with mocked API"""
# Create test CSV
csv_file = tmp_path / "test.csv"
csv_file.write_text(
"Email,Entitlement Display Name\n"
"user1@example.com,\"CN=existing-group,OU=Groups,DC=example,DC=com\"\n"
"user2@example.com,\"CN=new-group,OU=Groups,DC=example,DC=com\"\n"
)
# Run sync
result = runner.invoke(cli, ['sync', '--csv', str(csv_file)])
# Verify results
assert result.exit_code == 0
assert "created=1" in result.output # new-group created
assert "updated=1" in result.output # existing-group updated
# Verify API calls
assert mock_xc_api.call_count == 3 # GET + POST + PUT
Running Integration Tests:
# Run all integration tests
pytest tests/integration/ -v
# Run with API mock verification
pytest tests/integration/ --log-cli-level=DEBUG
End-to-End Testing Strategy¶
Objective: Verify complete system functionality with real or near-real F5 XC environment
Options:
Option 1: F5 XC Sandbox/Staging Environment (Recommended)
# Configure for staging environment
export XC_API_URL="https://tenant.staging.volterra.us"
export TENANT_ID="test-tenant"
export VOLT_API_P12_FILE="staging-cert.p12"
export VES_P12_PASSWORD="test-password" # pragma: allowlist secret
# Run E2E test
pytest tests/e2e/ --e2e-env=staging
Option 2: Mock F5 XC Server with Docker
# Start mock F5 XC API server
docker-compose -f tests/e2e/docker-compose.yml up -d
# Run E2E tests against mock server
pytest tests/e2e/ --e2e-env=mock
# Cleanup
docker-compose -f tests/e2e/docker-compose.yml down
Key E2E Test Scenarios:
- First-Time Setup
- Run setup script with P12 file
- Verify .env created correctly
- Verify certificates extracted
-
Run first sync successfully
-
Large Dataset Performance
- Generate synthetic CSV with 10,000+ rows
- Measure execution time
- Verify memory usage within limits
-
Validate all operations completed
-
Prune Operation
- Create groups in F5 XC not in CSV
- Run sync with --prune
- Verify orphaned groups deleted
-
Verify CSV groups remain
-
Error Recovery
- Simulate network interruptions
- Verify retry mechanism works
- Verify partial completion handling
-
Verify resumption succeeds
-
Multi-Environment
- Test production configuration
- Test staging configuration
- Verify environment detection
- Verify SSL warnings for staging
Running E2E Tests:
# Run all E2E tests (requires staging environment)
pytest tests/e2e/ --e2e-env=staging -v
# Run specific scenario
pytest tests/e2e/test_large_dataset.py -v
# Run with performance profiling
pytest tests/e2e/ --e2e-env=staging --profile
Related Documentation¶
- Operational Workflows - Step-by-step operational procedures
- Deployment Guide - Deployment scenarios and automation
- Troubleshooting Guide - Common issues and resolutions
- GitHub Actions Guide - CI/CD automation with GitHub
- Jenkins Guide - CI/CD automation with Jenkins