Skip to content

Commit cbd6110

Browse files
Nathan ParkerNathan Parker
authored andcommitted
Add E2E test files to git and update CI/CD dependencies
1 parent 989199d commit cbd6110

File tree

2 files changed

+646
-0
lines changed

2 files changed

+646
-0
lines changed

tests/integration/README.md

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# End-to-End Integration Tests
2+
3+
This directory contains comprehensive end-to-end tests for validating deployed Cloud Run services.
4+
5+
## Overview
6+
7+
The E2E test suite validates:
8+
- Health and system endpoints
9+
- Authentication and authorization
10+
- Utility and metadata endpoints
11+
- Read operations (list, search, get)
12+
- Create operations (OKH, OKW)
13+
- Match operations
14+
- Error handling
15+
- Metrics endpoints
16+
17+
## Prerequisites
18+
19+
- Python 3.11+
20+
- `pytest` and `requests` packages
21+
- Access to a deployed service URL
22+
- Authentication credentials (API key or GCP identity token)
23+
24+
## Running Tests
25+
26+
### Local Execution
27+
28+
**Important**: The Cloud Run service requires authentication. You need to provide either:
29+
- A GCP identity token (recommended for GCP Cloud Run)
30+
- An API key (if configured)
31+
32+
```bash
33+
# Set the service URL
34+
export SERVICE_URL=https://supply-graph-ai-1085931013579.us-west1.run.app
35+
36+
# Option 1: Use GCP identity token (automatic if gcloud is configured)
37+
# The tests will automatically try to get a token using 'gcloud auth print-identity-token'
38+
# Just make sure you're authenticated: gcloud auth login
39+
export USE_AUTH=true
40+
41+
# Option 2: Manually provide identity token
42+
export IDENTITY_TOKEN=$(gcloud auth print-identity-token)
43+
export USE_AUTH=true
44+
45+
# Option 3: Use API key (if your service supports it)
46+
export API_KEY=your-api-key
47+
export USE_AUTH=true
48+
49+
# Option 4: Disable authentication (only if service allows unauthenticated access)
50+
export USE_AUTH=false
51+
52+
# Install dependencies
53+
pip install pytest requests
54+
55+
# Run all tests
56+
pytest tests/integration/test_cloud_run_e2e.py -v
57+
58+
# Run specific test class
59+
pytest tests/integration/test_cloud_run_e2e.py::TestHealthEndpoints -v
60+
61+
# Run with detailed output
62+
pytest tests/integration/test_cloud_run_e2e.py -v -s
63+
```
64+
65+
### Using Shell Script
66+
67+
```bash
68+
# Set environment variables
69+
export SERVICE_URL=https://supply-graph-ai-1085931013579.us-west1.run.app
70+
export API_KEY=your-api-key # Optional
71+
export IDENTITY_TOKEN=your-gcp-token # Optional
72+
export USE_AUTH=true
73+
74+
# Run the shell script
75+
./scripts/test-cloud-run-e2e.sh
76+
```
77+
78+
### GCP Cloud Run Authentication
79+
80+
For GCP Cloud Run services with `--no-allow-unauthenticated`, use identity tokens:
81+
82+
```bash
83+
# Get identity token
84+
IDENTITY_TOKEN=$(gcloud auth print-identity-token)
85+
86+
# Run tests
87+
export SERVICE_URL=https://your-service.run.app
88+
export IDENTITY_TOKEN="${IDENTITY_TOKEN}"
89+
export USE_AUTH=true
90+
91+
pytest tests/integration/test_cloud_run_e2e.py -v
92+
```
93+
94+
## Test Structure
95+
96+
### Test Classes
97+
98+
- **TestHealthEndpoints**: Basic health checks and system endpoints
99+
- **TestAuthentication**: Authentication and authorization validation
100+
- **TestUtilityEndpoints**: Utility and metadata endpoints
101+
- **TestReadOperations**: List, search, and get operations
102+
- **TestCreateOperations**: Create OKH and OKW resources
103+
- **TestMatchOperations**: Matching OKH to OKW facilities
104+
- **TestErrorHandling**: Error response validation
105+
- **TestMetricsEndpoints**: Metrics endpoint validation
106+
107+
### Test Data
108+
109+
Tests create temporary resources (OKH manifests, OKW facilities) and automatically clean them up after all tests complete.
110+
111+
## CI/CD Integration
112+
113+
The E2E tests are automatically run in the CI/CD pipeline after successful deployment. See `.github/workflows/ci-cd.yml` for details.
114+
115+
## Troubleshooting
116+
117+
### Authentication Failures
118+
119+
If tests fail with 401 errors:
120+
- Verify `IDENTITY_TOKEN` or `API_KEY` is set correctly
121+
- Check that the service allows authenticated requests
122+
- For GCP, ensure `gcloud auth print-identity-token` works
123+
124+
### Connection Errors
125+
126+
If tests fail to connect:
127+
- Verify `SERVICE_URL` is correct
128+
- Check network connectivity
129+
- Ensure the service is deployed and running
130+
131+
### Test Failures
132+
133+
If specific tests fail:
134+
- Check the service logs for errors
135+
- Verify the service has required dependencies (storage, secrets)
136+
- Ensure test data can be created (storage permissions)
137+
138+
## Adding New Tests
139+
140+
To add new E2E tests:
141+
142+
1. Add a new test method to the appropriate test class
143+
2. Use the `base_url` and `auth_headers` fixtures
144+
3. Follow the existing test patterns
145+
4. Add cleanup if creating resources
146+
147+
Example:
148+
149+
```python
150+
def test_new_endpoint(self, base_url, auth_headers):
151+
"""Test description"""
152+
response = requests.get(
153+
f"{base_url}/v1/api/new-endpoint",
154+
headers=auth_headers
155+
)
156+
assert response.status_code == 200
157+
data = response.json()
158+
assert "expected_field" in data
159+
```
160+

0 commit comments

Comments
 (0)