Skip to content

Commit 16ae4e8

Browse files
authored
add simple CI build for WireMock extension (#8)
1 parent e153430 commit 16ae4e8

6 files changed

Lines changed: 76 additions & 10 deletions

File tree

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ on:
55
branches:
66
- main
77
paths:
8-
- 'localstack-wiremock/**'
8+
- 'localstack-typedb/**'
99
push:
1010
branches:
1111
- main
1212
paths:
13-
- 'localstack-wiremock/**'
13+
- 'localstack-typedb/**'
1414
workflow_dispatch:
1515

1616
env:
@@ -19,14 +19,14 @@ env:
1919

2020
jobs:
2121
integration-tests:
22-
name: Run Integration Tests
22+
name: Run TypeDB Extension Tests
2323
runs-on: ubuntu-latest
2424
timeout-minutes: 10
2525
steps:
2626
- name: Checkout
2727
uses: actions/checkout@v4
2828

29-
- name: Setup LocalStack and extension
29+
- name: Set up LocalStack and extension
3030
run: |
3131
cd localstack-typedb
3232
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: LocalStack WireMock Extension Tests
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
paths:
8+
- 'localstack-wiremock/**'
9+
push:
10+
branches:
11+
- main
12+
paths:
13+
- 'localstack-wiremock/**'
14+
workflow_dispatch:
15+
16+
env:
17+
LOCALSTACK_DISABLE_EVENTS: "1"
18+
LOCALSTACK_AUTH_TOKEN: ${{ secrets.TEST_LOCALSTACK_AUTH_TOKEN }}
19+
20+
jobs:
21+
integration-tests:
22+
name: Run WireMock Extension Tests
23+
runs-on: ubuntu-latest
24+
timeout-minutes: 10
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v4
28+
29+
- name: Set up Terraform
30+
uses: hashicorp/setup-terraform@v3
31+
32+
- name: Set up LocalStack and extension
33+
run: |
34+
cd localstack-wiremock
35+
36+
docker pull localstack/localstack-pro &
37+
docker pull wiremock/wiremock &
38+
docker pull public.ecr.aws/lambda/python:3.9 &
39+
pip install localstack terraform-local awscli-local[ver1]
40+
41+
make install
42+
make dist
43+
localstack extensions -v install file://$(ls ./dist/localstack_wiremock-*.tar.gz)
44+
45+
DEBUG=1 localstack start -d
46+
localstack wait
47+
48+
- name: Run sample app test
49+
run: |
50+
cd localstack-wiremock
51+
make sample
52+
53+
- name: Print logs
54+
if: always()
55+
run: |
56+
localstack logs
57+
localstack stop

localstack-wiremock/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,14 @@ test: ## Run integration tests (requires LocalStack running with the Extens
3939
$(VENV_RUN); pytest tests $(PYTEST_ARGS)
4040

4141
sample: ## Deploy sample app
42+
echo "Creating stubs in WireMock ..."
4243
bin/create-stubs.sh
44+
echo "Deploying sample app into LocalStack via Terraform ..."
4345
(cd sample-app; tflocal init; tflocal apply -auto-approve)
4446
apiId=$$(awslocal apigateway get-rest-apis | jq -r '.items[0].id'); \
45-
curl -k https://$$apiId.execute-api.us-east-1.localhost.localstack.cloud/dev/time-off
47+
endpoint=https://$$apiId.execute-api.us-east-1.localhost.localstack.cloud/dev/time-off; \
48+
echo "Invoking local API Gateway endpoint: $$endpoint"; \
49+
curl -k -v $$endpoint | grep time_off_date
4650

4751
clean-dist: clean
4852
rm -rf dist/

localstack-wiremock/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
WireMock on LocalStack
2-
===============================
2+
========================
33

4-
This repo contains a [LocalStack Extension](https://github.com/localstack/localstack-extensions) that facilitates developing WireMock-based applications locally.
4+
This repo contains a [LocalStack Extension](https://github.com/localstack/localstack-extensions) that facilitates developing [WireMock](https://wiremock.org)-based applications locally.
55

66
## Prerequisites
77

localstack-wiremock/localstack_wiremock/extension.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ class WireMockExtension(ProxiedDockerContainerExtension):
77
HOST = "wiremock.<domain>"
88
# name of the Docker image to spin up
99
DOCKER_IMAGE = "wiremock/wiremock"
10+
# name of the container
11+
CONTAINER_NAME = "ls-wiremock"
1012

1113
def __init__(self):
1214
super().__init__(
1315
image_name=self.DOCKER_IMAGE,
1416
container_ports=[8080],
17+
container_name=self.CONTAINER_NAME,
1518
host=self.HOST,
1619
)

localstack-wiremock/sample-app/src/handler.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ def get_time_off(event, context):
88
and returns a transformed JSON response.
99
"""
1010
try:
11-
# Define the mock API endpoint URL (hardcoding `host.docker.internal` for now)
12-
# url = "http://wiremock.localhost.localstack.cloud:8080/company/time-offs/534813865"
13-
url = "http://host.docker.internal:8080/company/time-offs/534813865"
11+
# Define the mock API endpoint URL (hardcoding `wiremock.localhost.localstack.cloud` for
12+
# local dev for now - could be injected via env variables in the future ...)
13+
url = "http://wiremock.localhost.localstack.cloud:4566/company/time-offs/534813865"
1414

1515
# Make a GET request to the mock API
1616
response = requests.get(url, timeout=5)
@@ -41,6 +41,7 @@ def get_time_off(event, context):
4141
"message": "Could not connect to the downstream HR service.",
4242
"error": str(e),
4343
}
44+
print("Error:", error_message)
4445
return {
4546
"statusCode": 503, # Service Unavailable
4647
"headers": {"Content-Type": "application/json"},
@@ -49,6 +50,7 @@ def get_time_off(event, context):
4950
except Exception as e:
5051
# Handle other unexpected errors (e.g., JSON parsing issues, programming errors)
5152
error_message = {"message": "An unexpected error occurred.", "error": str(e)}
53+
print("Error:", error_message)
5254
return {
5355
"statusCode": 500, # Internal Server Error
5456
"headers": {"Content-Type": "application/json"},

0 commit comments

Comments
 (0)