Skip to content

Commit c17c95c

Browse files
committed
feat: add Cloud fixture generation script and documentation
Added infrastructure for Cloud API fixture generation with important notes about costs and data sanitization. Changes: - Created scripts/generate-cloud-fixtures.sh for capturing Cloud API responses - Added crates/redis-cloud/tests/fixtures/README.md documenting approach - Explains why Cloud fixtures require careful handling (costs, PII) - Documents current wiremock-based testing approach Note: Cloud fixtures not generated yet as it requires: - Active Cloud account with resources - Manual data sanitization - Billable infrastructure Enterprise fixtures are complete and working (8/8 tests passing).
1 parent 412309a commit c17c95c

File tree

2 files changed

+147
-0
lines changed

2 files changed

+147
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Redis Cloud API Fixtures
2+
3+
## Current Status
4+
5+
The Cloud API fixtures directory currently only contains the OpenAPI specification.
6+
7+
## Why No Real Fixtures Yet?
8+
9+
Unlike Enterprise API (which uses Docker for testing), Cloud API fixtures require:
10+
1. A real Cloud account with active resources
11+
2. Billable subscriptions and databases
12+
3. Careful sanitization of account data before committing
13+
14+
## Generating Cloud Fixtures
15+
16+
When you have a Cloud account with test resources, you can generate fixtures:
17+
18+
```bash
19+
export REDIS_CLOUD_API_KEY="your-key"
20+
export REDIS_CLOUD_SECRET_KEY="your-secret"
21+
./scripts/generate-cloud-fixtures.sh
22+
```
23+
24+
**Important**: Review all generated fixtures for sensitive data before committing!
25+
26+
## Current Testing Approach
27+
28+
Cloud API tests currently use wiremock with inline JSON mocks. This approach:
29+
- ✅ Works well for testing
30+
- ✅ No infrastructure required
31+
- ✅ No costs
32+
- ⚠️ Doesn't catch type mismatches from real API responses
33+
34+
## Future Work
35+
36+
To get the full benefits of fixture-based testing for Cloud:
37+
1. Use a test Cloud account with minimal resources
38+
2. Generate fixtures from real API responses
39+
3. Sanitize account/subscription IDs
40+
4. Add validation tests like Enterprise has

scripts/generate-cloud-fixtures.sh

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#!/usr/bin/env bash
2+
# Generate test fixtures from actual Redis Cloud API responses
3+
# This script captures real API responses to ensure our type definitions match reality
4+
5+
set -euo pipefail
6+
7+
# Configuration
8+
REDIS_CLOUD_API_KEY="${REDIS_CLOUD_API_KEY:-}"
9+
REDIS_CLOUD_SECRET_KEY="${REDIS_CLOUD_SECRET_KEY:-}"
10+
REDIS_CLOUD_BASE_URL="${REDIS_CLOUD_BASE_URL:-https://api.redislabs.com/v1}"
11+
OUTPUT_DIR="crates/redis-cloud/tests/fixtures"
12+
13+
# Colors for output
14+
RED='\033[0;31m'
15+
GREEN='\033[0;32m'
16+
YELLOW='\033[1;33m'
17+
NC='\033[0m' # No Color
18+
19+
# Check credentials
20+
if [ -z "$REDIS_CLOUD_API_KEY" ] || [ -z "$REDIS_CLOUD_SECRET_KEY" ]; then
21+
echo -e "${RED}Error: REDIS_CLOUD_API_KEY and REDIS_CLOUD_SECRET_KEY must be set${NC}"
22+
echo "Export these environment variables with your Redis Cloud credentials"
23+
exit 1
24+
fi
25+
26+
# Ensure output directory exists
27+
mkdir -p "$OUTPUT_DIR"
28+
29+
echo "Generating Redis Cloud API fixtures..."
30+
echo "URL: $REDIS_CLOUD_BASE_URL"
31+
echo "Output: $OUTPUT_DIR"
32+
echo ""
33+
echo -e "${YELLOW}WARNING: This will make real API calls to your Cloud account${NC}"
34+
echo -e "${YELLOW}No resources will be created, only GET requests${NC}"
35+
echo ""
36+
37+
# Function to capture API response
38+
capture_endpoint() {
39+
local endpoint="$1"
40+
local filename="$2"
41+
local description="$3"
42+
43+
echo -n "Capturing $description... "
44+
45+
if curl -s -f \
46+
-H "x-api-key: $REDIS_CLOUD_API_KEY" \
47+
-H "x-api-secret-key: $REDIS_CLOUD_SECRET_KEY" \
48+
"$REDIS_CLOUD_BASE_URL$endpoint" \
49+
-o "$OUTPUT_DIR/$filename" 2>/dev/null; then
50+
51+
# Validate it's valid JSON
52+
if jq empty "$OUTPUT_DIR/$filename" 2>/dev/null; then
53+
echo -e "${GREEN}${NC}"
54+
else
55+
echo -e "${RED}✗ Invalid JSON${NC}"
56+
rm "$OUTPUT_DIR/$filename"
57+
return 1
58+
fi
59+
else
60+
echo -e "${YELLOW}⚠ Endpoint not available or no data${NC}"
61+
return 1
62+
fi
63+
}
64+
65+
# Account information
66+
capture_endpoint "/account" "account.json" "Account info"
67+
68+
# Subscriptions
69+
capture_endpoint "/subscriptions" "subscriptions_list.json" "Subscriptions list"
70+
71+
# Databases (flexible/pro)
72+
capture_endpoint "/subscriptions" "databases_for_subscription.json" "Databases for subscription" || true
73+
74+
# Cloud accounts
75+
capture_endpoint "/cloud-accounts" "cloud_accounts_list.json" "Cloud accounts list"
76+
77+
# Payment methods
78+
capture_endpoint "/payment-methods" "payment_methods_list.json" "Payment methods" || true
79+
80+
# Regions
81+
capture_endpoint "/regions" "regions_list.json" "Regions list" || true
82+
83+
# Tasks (may be empty)
84+
capture_endpoint "/tasks" "tasks_list.json" "Tasks list" || true
85+
86+
# Users
87+
capture_endpoint "/users" "users_list.json" "Users list"
88+
89+
# ACLs
90+
capture_endpoint "/acls" "acls_list.json" "ACLs list" || true
91+
92+
# Fixed (Essentials) subscriptions
93+
capture_endpoint "/fixed/subscriptions" "fixed_subscriptions_list.json" "Fixed subscriptions" || true
94+
95+
# API Keys (careful - these are sensitive, only if needed for testing)
96+
# capture_endpoint "/account/api-keys" "api_keys_list.json" "API keys list" || true
97+
98+
echo ""
99+
echo "Fixture generation complete!"
100+
echo "Captured fixtures in: $OUTPUT_DIR"
101+
echo ""
102+
echo -e "${YELLOW}IMPORTANT: Review fixtures for sensitive data before committing!${NC}"
103+
echo "- Remove account IDs, subscription IDs if needed"
104+
echo "- Check for any PII or secrets"
105+
echo ""
106+
echo "Files generated:"
107+
ls -lh "$OUTPUT_DIR"/*.json 2>/dev/null | awk '{print " " $9 " (" $5 ")"}'

0 commit comments

Comments
 (0)