diff --git a/.github/workflows/test.yml b/.github/workflows/test-typedb.yml similarity index 87% rename from .github/workflows/test.yml rename to .github/workflows/test-typedb.yml index 3200b25..45c9fa9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test-typedb.yml @@ -5,12 +5,12 @@ on: branches: - main paths: - - 'localstack-wiremock/**' + - 'localstack-typedb/**' push: branches: - main paths: - - 'localstack-wiremock/**' + - 'localstack-typedb/**' workflow_dispatch: env: @@ -19,14 +19,14 @@ env: jobs: integration-tests: - name: Run Integration Tests + name: Run TypeDB Extension Tests runs-on: ubuntu-latest timeout-minutes: 10 steps: - name: Checkout uses: actions/checkout@v4 - - name: Setup LocalStack and extension + - name: Set up LocalStack and extension run: | cd localstack-typedb diff --git a/.github/workflows/test-wiremock.yml b/.github/workflows/test-wiremock.yml new file mode 100644 index 0000000..5bf7c0d --- /dev/null +++ b/.github/workflows/test-wiremock.yml @@ -0,0 +1,57 @@ +name: LocalStack WireMock Extension Tests + +on: + pull_request: + branches: + - main + paths: + - 'localstack-wiremock/**' + push: + branches: + - main + paths: + - 'localstack-wiremock/**' + workflow_dispatch: + +env: + LOCALSTACK_DISABLE_EVENTS: "1" + LOCALSTACK_AUTH_TOKEN: ${{ secrets.TEST_LOCALSTACK_AUTH_TOKEN }} + +jobs: + integration-tests: + name: Run WireMock Extension Tests + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Terraform + uses: hashicorp/setup-terraform@v3 + + - name: Set up LocalStack and extension + run: | + cd localstack-wiremock + + docker pull localstack/localstack-pro & + docker pull wiremock/wiremock & + docker pull public.ecr.aws/lambda/python:3.9 & + pip install localstack terraform-local awscli-local[ver1] + + make install + make dist + localstack extensions -v install file://$(ls ./dist/localstack_wiremock-*.tar.gz) + + DEBUG=1 localstack start -d + localstack wait + + - name: Run sample app test + run: | + cd localstack-wiremock + make sample + + - name: Print logs + if: always() + run: | + localstack logs + localstack stop diff --git a/localstack-wiremock/Makefile b/localstack-wiremock/Makefile index cb86e37..28a654f 100644 --- a/localstack-wiremock/Makefile +++ b/localstack-wiremock/Makefile @@ -39,10 +39,14 @@ test: ## Run integration tests (requires LocalStack running with the Extens $(VENV_RUN); pytest tests $(PYTEST_ARGS) sample: ## Deploy sample app + echo "Creating stubs in WireMock ..." bin/create-stubs.sh + echo "Deploying sample app into LocalStack via Terraform ..." (cd sample-app; tflocal init; tflocal apply -auto-approve) apiId=$$(awslocal apigateway get-rest-apis | jq -r '.items[0].id'); \ - curl -k https://$$apiId.execute-api.us-east-1.localhost.localstack.cloud/dev/time-off + endpoint=https://$$apiId.execute-api.us-east-1.localhost.localstack.cloud/dev/time-off; \ + echo "Invoking local API Gateway endpoint: $$endpoint"; \ + curl -k -v $$endpoint | grep time_off_date clean-dist: clean rm -rf dist/ diff --git a/localstack-wiremock/README.md b/localstack-wiremock/README.md index 6295ecf..f00b1fa 100644 --- a/localstack-wiremock/README.md +++ b/localstack-wiremock/README.md @@ -1,7 +1,7 @@ WireMock on LocalStack -=============================== +======================== -This repo contains a [LocalStack Extension](https://github.com/localstack/localstack-extensions) that facilitates developing WireMock-based applications locally. +This repo contains a [LocalStack Extension](https://github.com/localstack/localstack-extensions) that facilitates developing [WireMock](https://wiremock.org)-based applications locally. ## Prerequisites diff --git a/localstack-wiremock/localstack_wiremock/extension.py b/localstack-wiremock/localstack_wiremock/extension.py index becc135..b899051 100644 --- a/localstack-wiremock/localstack_wiremock/extension.py +++ b/localstack-wiremock/localstack_wiremock/extension.py @@ -7,10 +7,13 @@ class WireMockExtension(ProxiedDockerContainerExtension): HOST = "wiremock." # name of the Docker image to spin up DOCKER_IMAGE = "wiremock/wiremock" + # name of the container + CONTAINER_NAME = "ls-wiremock" def __init__(self): super().__init__( image_name=self.DOCKER_IMAGE, container_ports=[8080], + container_name=self.CONTAINER_NAME, host=self.HOST, ) diff --git a/localstack-wiremock/sample-app/src/handler.py b/localstack-wiremock/sample-app/src/handler.py index 61c2b3c..fc31bb1 100644 --- a/localstack-wiremock/sample-app/src/handler.py +++ b/localstack-wiremock/sample-app/src/handler.py @@ -8,9 +8,9 @@ def get_time_off(event, context): and returns a transformed JSON response. """ try: - # Define the mock API endpoint URL (hardcoding `host.docker.internal` for now) - # url = "http://wiremock.localhost.localstack.cloud:8080/company/time-offs/534813865" - url = "http://host.docker.internal:8080/company/time-offs/534813865" + # Define the mock API endpoint URL (hardcoding `wiremock.localhost.localstack.cloud` for + # local dev for now - could be injected via env variables in the future ...) + url = "http://wiremock.localhost.localstack.cloud:4566/company/time-offs/534813865" # Make a GET request to the mock API response = requests.get(url, timeout=5) @@ -41,6 +41,7 @@ def get_time_off(event, context): "message": "Could not connect to the downstream HR service.", "error": str(e), } + print("Error:", error_message) return { "statusCode": 503, # Service Unavailable "headers": {"Content-Type": "application/json"}, @@ -49,6 +50,7 @@ def get_time_off(event, context): except Exception as e: # Handle other unexpected errors (e.g., JSON parsing issues, programming errors) error_message = {"message": "An unexpected error occurred.", "error": str(e)} + print("Error:", error_message) return { "statusCode": 500, # Internal Server Error "headers": {"Content-Type": "application/json"},