-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_integration.py
More file actions
111 lines (93 loc) · 3.82 KB
/
test_integration.py
File metadata and controls
111 lines (93 loc) · 3.82 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
#!/usr/bin/env python3
"""
Integration test to verify that the application properly validates
environment variables at startup and prevents execution without them.
"""
import os
import sys
import subprocess
def test_cloud_engineer_agent_import():
"""Test that cloud_engineer_agent.py validates environment on import."""
print("="*80)
print("Test: Import cloud_engineer_agent.py without environment variables")
print("="*80)
# Create environment without AWS variables
test_env = os.environ.copy()
for key in list(test_env.keys()):
if key.startswith('AWS_'):
del test_env[key]
# Try to import the module
result = subprocess.run(
[sys.executable, '-c', 'import cloud_engineer_agent'],
env=test_env,
capture_output=True,
text=True,
cwd='/projects/sandbox/cloudeng-strands-agent',
timeout=10
)
print(f"\nExit Code: {result.returncode}")
print(f"Expected: Non-zero (should fail)")
if result.returncode != 0:
print("✓ Test PASSED - Module correctly refused to load without credentials")
print("\nError Output Preview:")
print(result.stderr[:500] if len(result.stderr) > 500 else result.stderr)
return True
else:
print("✗ Test FAILED - Module loaded without credentials (should have failed)")
return False
def test_cloud_engineer_agent_with_credentials():
"""Test that cloud_engineer_agent.py can be imported with valid environment."""
print("\n" + "="*80)
print("Test: Import cloud_engineer_agent.py WITH environment variables")
print("="*80)
# Create environment with AWS variables
test_env = os.environ.copy()
test_env['AWS_REGION'] = 'us-east-1'
test_env['AWS_ACCESS_KEY_ID'] = 'AKIAIOSFODNN7EXAMPLE'
test_env['AWS_SECRET_ACCESS_KEY'] = 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY'
# Try to import the module (it may fail on MCP client initialization, but env validation should pass)
result = subprocess.run(
[sys.executable, '-c', 'from env_validator import validate_environment_variables; validate_environment_variables(); print("ENV VALIDATION PASSED")'],
env=test_env,
capture_output=True,
text=True,
cwd='/projects/sandbox/cloudeng-strands-agent',
timeout=10
)
print(f"\nExit Code: {result.returncode}")
print(f"Expected: 0 (should succeed)")
if result.returncode == 0 and "ENV VALIDATION PASSED" in result.stdout:
print("✓ Test PASSED - Environment validation passed with credentials")
print("\nOutput Preview:")
print(result.stdout)
return True
else:
print("✗ Test FAILED - Environment validation failed even with credentials")
print(f"\nStdout:\n{result.stdout}")
print(f"\nStderr:\n{result.stderr}")
return False
def main():
"""Run integration tests."""
print("Starting Integration Tests for Environment Validation")
print("="*80 + "\n")
all_passed = True
# Test 1: Verify startup fails without credentials
all_passed &= test_cloud_engineer_agent_import()
# Test 2: Verify startup succeeds with credentials
all_passed &= test_cloud_engineer_agent_with_credentials()
# Summary
print("\n" + "="*80)
print("Integration Test Summary")
print("="*80)
if all_passed:
print("✓ All integration tests PASSED")
print("\nConclusion:")
print("- Application correctly validates environment variables at startup")
print("- Missing credentials cause immediate failure with clear error messages")
print("- Valid credentials allow the application to proceed")
return 0
else:
print("✗ Some integration tests FAILED")
return 1
if __name__ == '__main__':
sys.exit(main())