Skip to content

Commit 0c34078

Browse files
committed
add cloud pods workflow & integration tests
1 parent 42a051e commit 0c34078

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed

.github/workflows/pods.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Deploy using Cloud Pods
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
cloud-pods-test:
13+
name: Setup infrastructure using Cloud Pods
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout the code
17+
uses: actions/checkout@v4
18+
19+
- name: Install Python
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: '3.10'
23+
24+
- name: Start LocalStack
25+
uses: LocalStack/setup-localstack@main
26+
with:
27+
image-tag: 'latest'
28+
use-pro: 'true'
29+
env:
30+
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }}
31+
32+
- name: Load the Cloud Pod
33+
uses: LocalStack/setup-localstack/cloud-pods@main
34+
with:
35+
name: loan-broker-infra
36+
action: load
37+
env:
38+
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }}
39+
40+
- name: Run integration tests
41+
run: |
42+
pip3 install boto3 pytest
43+
pytest
44+
env:
45+
AWS_DEFAULT_REGION: us-east-1
46+
AWS_REGION: us-east-1
47+
AWS_ACCESS_KEY_ID: test
48+
AWS_SECRET_ACCESS_KEY: test

tests/test_infra.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import time
2+
import json
3+
import pytest
4+
import boto3
5+
6+
@pytest.fixture
7+
def stepfunctions_client():
8+
return boto3.client(
9+
"stepfunctions", region_name="us-east-1", endpoint_url="http://localhost:4566"
10+
)
11+
12+
@pytest.fixture
13+
def dynamodb_client():
14+
return boto3.client(
15+
"dynamodb", region_name="us-east-1", endpoint_url="http://localhost:4566"
16+
)
17+
18+
def test_loan_broker_workflow(stepfunctions_client, dynamodb_client):
19+
response = stepfunctions_client.list_state_machines()
20+
state_machines = response["stateMachines"]
21+
22+
state_machine_arn = None
23+
for state_machine in state_machines:
24+
if state_machine["name"].startswith(
25+
"LoanBroker-RecipientList-Stack-LoanBroker"
26+
):
27+
state_machine_arn = state_machine["stateMachineArn"]
28+
break
29+
30+
assert (
31+
state_machine_arn is not None
32+
), "State machine with specified prefix not found"
33+
34+
dynamodb_client.put_item(
35+
TableName="LoanBrokerBanksTable",
36+
Item={
37+
"Type": {"S": "Home"},
38+
"BankAddress": {
39+
"L": [
40+
{"S": "BankRecipientPremium"},
41+
{"S": "BankRecipientUniversal"},
42+
{"S": "BankRecipientPawnshop"},
43+
]
44+
},
45+
},
46+
)
47+
48+
start_response = stepfunctions_client.start_execution(
49+
stateMachineArn=state_machine_arn,
50+
name="cli-test-run",
51+
input='{"SSN": "123-45-6789", "Amount": 500000, "Term": 30}',
52+
)
53+
execution_arn = start_response["executionArn"]
54+
55+
time.sleep(10)
56+
57+
describe_response = stepfunctions_client.describe_execution(
58+
executionArn=execution_arn
59+
)
60+
output_json = json.loads(describe_response["output"])
61+
62+
assert "SSN" in output_json
63+
assert "Amount" in output_json
64+
assert "Term" in output_json
65+
assert "Credit" in output_json
66+
assert "Banks" in output_json
67+
assert "Quotes" in output_json

0 commit comments

Comments
 (0)