Skip to content

Commit 1e4c6a2

Browse files
whummerclaude
andcommitted
Fix CI: update workflow and E2E tests for current app
- workflow: deploy app (build ECR image + tflocal apply) then run pytest - tests: update status checks from 'processed' to 'fulfilled', increase timeout for ECS pipeline, add products test, update item names Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent c5898be commit 1e4c6a2

2 files changed

Lines changed: 52 additions & 27 deletions

File tree

.github/workflows/build-test.yml

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,45 @@ jobs:
1313
- name: Checkout
1414
uses: actions/checkout@v2
1515

16-
- name: Start up LocalStack
17-
env:
18-
LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
16+
- name: Install tools
1917
run: |
20-
docker pull localstack/localstack-pro &
18+
pip install --pre localstack awscli-local[ver1] terraform-local pytest requests
2119
22-
# install CLI tools
23-
pip install --pre localstack localstack-ext awscli-local[ver1]
24-
25-
# start LocalStack
26-
DEBUG=1 localstack start -d
27-
localstack wait
20+
# Terraform
21+
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
22+
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" \
23+
| sudo tee /etc/apt/sources.list.d/hashicorp.list
24+
sudo apt-get update -qq && sudo apt-get install -y terraform
2825
29-
- name: Run simple test
26+
- name: Start LocalStack
3027
env:
3128
LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
3229
run: |
33-
set -e
30+
docker pull localstack/localstack-pro &
31+
DEBUG=1 LOCALSTACK_APPINSPECTOR_ENABLE=1 localstack start -d
32+
localstack wait
3433
35-
# deploy test resources
36-
(cd 00-hello-world; ./deploy.sh)
34+
- name: Build fulfillment image
35+
run: |
36+
ECR_REGISTRY="000000000000.dkr.ecr.us-east-1.localhost.localstack.cloud:4566"
37+
awslocal ecr create-repository --repository-name fulfillment 2>/dev/null || true
38+
awslocal ecr get-login-password | \
39+
docker login --username AWS --password-stdin "$ECR_REGISTRY"
40+
docker build -t "$ECR_REGISTRY/fulfillment:latest" 01-serverless-app/services/fulfillment
41+
docker push "$ECR_REGISTRY/fulfillment:latest"
42+
43+
- name: Deploy app via Terraform
44+
run: |
45+
cd 01-serverless-app/terraform
46+
tflocal init
47+
tflocal apply -auto-approve
3748
38-
# run assertion
39-
curl http://testwebsite.s3-website.localhost.localstack.cloud:4566 | grep 'You are running LocalStack'
49+
- name: Run E2E tests
50+
run: |
51+
cd 02-e2e-testing && pytest tests/ -v
4052
4153
- name: Print LocalStack logs
54+
if: always()
4255
run: |
4356
localstack logs
4457
localstack stop

02-e2e-testing/tests/test_order_flow.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,51 @@
44

55

66
def test_create_order_returns_order_id(api_endpoint):
7-
resp = requests.post(f"{api_endpoint}/orders", json={"item": "book", "quantity": 2})
7+
resp = requests.post(f"{api_endpoint}/orders", json={"item": "LocalStack T-Shirt", "quantity": 2})
88
assert resp.status_code == 201
99
data = resp.json()
1010
assert "order_id" in data
1111
assert data["status"] == "pending"
1212

1313

1414
def test_order_persisted_in_dynamodb(api_endpoint, dynamodb):
15-
resp = requests.post(f"{api_endpoint}/orders", json={"item": "mug", "quantity": 1})
15+
resp = requests.post(f"{api_endpoint}/orders", json={"item": "LocalStack Mug", "quantity": 1})
1616
order_id = resp.json()["order_id"]
1717

1818
table = dynamodb.Table("orders")
1919
item = table.get_item(Key={"order_id": order_id})["Item"]
20-
assert item["item"] == "mug"
20+
assert item["item"] == "LocalStack Mug"
2121
assert item["status"] == "pending"
2222

2323

24-
def test_order_processed_and_receipt_in_s3(api_endpoint, dynamodb, s3):
25-
resp = requests.post(f"{api_endpoint}/orders", json={"item": "t-shirt", "quantity": 3})
24+
def test_order_fulfilled_and_receipt_in_s3(api_endpoint, dynamodb, s3):
25+
resp = requests.post(f"{api_endpoint}/orders", json={"item": "LocalStack Hoodie", "quantity": 1})
26+
assert resp.status_code == 201
2627
order_id = resp.json()["order_id"]
2728

28-
# Wait for async SQS → Lambda processing (up to 10s)
29+
# Wait for full pipeline: SQS → Lambda → Step Functions → ECS (up to 60s)
2930
table = dynamodb.Table("orders")
30-
for _ in range(20):
31+
for _ in range(120):
3132
item = table.get_item(Key={"order_id": order_id})["Item"]
32-
if item["status"] == "processed":
33+
if item["status"] in ("fulfilled", "failed"):
3334
break
3435
time.sleep(0.5)
3536
else:
36-
raise AssertionError(f"Order {order_id} never reached 'processed' status")
37+
raise AssertionError(f"Order {order_id} never reached terminal status (last: {item['status']})")
38+
39+
assert item["status"] == "fulfilled", f"Expected fulfilled, got {item['status']}"
3740

38-
# Verify receipt uploaded to S3
41+
# Verify receipt uploaded to S3 by the ECS fulfillment task
3942
obj = s3.get_object(Bucket="order-receipts", Key=f"receipts/{order_id}.json")
4043
receipt = json.loads(obj["Body"].read())
4144
assert receipt["order_id"] == order_id
42-
assert receipt["status"] == "processed"
45+
assert receipt["status"] == "fulfilled"
46+
47+
48+
def test_products_listed(api_endpoint):
49+
resp = requests.get(f"{api_endpoint}/products")
50+
assert resp.status_code == 200
51+
products = resp.json()
52+
assert len(products) > 0
53+
names = [p["name"] for p in products]
54+
assert any("LocalStack" in n for n in names)

0 commit comments

Comments
 (0)