Skip to content

Commit 2430b14

Browse files
committed
test: ✨ add harness testing capability
1 parent 9eb1b46 commit 2430b14

6 files changed

Lines changed: 107 additions & 14 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: dockerized-test
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ '*' ]
8+
workflow_dispatch:
9+
10+
jobs:
11+
dockerized-test:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v3
16+
17+
- name: Build the image
18+
run: docker build . -t local/test -f Dockerfile.rie
19+
20+
- name: Run tests
21+
uses: aws/containerized-test-runner-for-aws-lambda@v1
22+
with:
23+
suiteFileArray: '["./dockerized-tests/*.json"]'
24+
dockerImageName: 'local/test'

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ target
33
lambda-runtime/libtest.rmeta
44
lambda-integration-tests/target
55
Cargo.lock
6+
.test-runner
67

78
# Built AWS Lambda zipfile
89
lambda.zip

Dockerfile.rie

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1-
FROM public.ecr.aws/lambda/provided:al2023
1+
FROM public.ecr.aws/lambda/provided:al2023 AS builder
22

33
RUN dnf install -y gcc make
44
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
55
ENV PATH="/root/.cargo/bin:${PATH}"
6-
ENV EXAMPLES="basic-lambda basic-lambda-concurrent"
6+
ENV EXAMPLES="basic-lambda"
77
ENV OUTPUT_DIR="/var/task"
88

9-
10-
ADD https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie /usr/local/bin/aws-lambda-rie
11-
RUN chmod +x /usr/local/bin/aws-lambda-rie
12-
139
COPY Cargo.* /build/
1410
COPY lambda-runtime /build/lambda-runtime
1511
COPY lambda-runtime-api-client /build/lambda-runtime-api-client
1612
COPY lambda-events /build/lambda-events
1713
COPY lambda-http /build/lambda-http
1814
COPY lambda-extension /build/lambda-extension
1915
COPY examples /build/examples
20-
COPY scripts/custom-lambda-entrypoint.sh /usr/local/bin/lambda-entrypoint
2116
COPY scripts/build-examples.sh /build/
2217

2318
WORKDIR /build
19+
RUN chmod +x build-examples.sh && ./build-examples.sh
2420

25-
RUN chmod +x /usr/local/bin/lambda-entrypoint
26-
RUN chmod +x build-examples.sh
21+
# Final Image
22+
FROM public.ecr.aws/lambda/provided:al2023
23+
24+
ADD https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie /usr/local/bin/aws-lambda-rie
25+
RUN chmod +x /usr/local/bin/aws-lambda-rie
2726

28-
# Build only basic-lambda example
29-
RUN ./build-examples.sh
27+
COPY scripts/custom-lambda-entrypoint.sh /usr/local/bin/lambda-entrypoint
28+
RUN chmod +x /usr/local/bin/lambda-entrypoint
3029

30+
COPY --from=builder /var/task /var/task
3131

3232
ENTRYPOINT ["/usr/local/bin/lambda-entrypoint"]
33-
CMD ["basic-lambda"]
33+
CMD ["basic-lambda"]

Dockerfile.test-runner

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM python:3.11-slim
2+
3+
# Install build dependencies for pyjq and Docker CLI
4+
RUN apt-get update && \
5+
apt-get install -y --no-install-recommends \
6+
gcc \
7+
g++ \
8+
make \
9+
autoconf \
10+
automake \
11+
libtool \
12+
ca-certificates \
13+
curl \
14+
&& curl -fsSL https://get.docker.com -o get-docker.sh \
15+
&& sh get-docker.sh \
16+
&& rm get-docker.sh \
17+
&& rm -rf /var/lib/apt/lists/*
18+
19+
WORKDIR /app
20+
21+
# Copy the test runner source
22+
COPY .test-runner/ .
23+
24+
# Install the test runner
25+
RUN pip install --no-cache-dir .
26+
27+
# Set the entrypoint
28+
ENTRYPOINT ["python", "-m", "containerized_test_runner.cli"]

Makefile

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ RIE_MAX_CONCURRENCY ?= 4
99
OUTPUT_DIR ?= /tmp/var-task
1010
EXAMPLES ?=
1111

12-
.PHONY: pr-check integration-tests check-event-features fmt build-examples test-rie test-rie-lmi nuke
12+
.PHONY: pr-check integration-tests check-event-features fmt build-examples test-rie test-rie-lmi nuke test-dockerized
1313

1414
define uppercase
1515
$(shell sed -r 's/(^|-)(\w)/\U\2/g' <<< $(1))
@@ -119,13 +119,34 @@ fmt:
119119
build-examples:
120120
./scripts/build-examples.sh
121121

122+
test-dockerized:
123+
@echo "Running dockerized tests locally..."
124+
@echo "Building Docker image..."
125+
docker build . -t local/test -f Dockerfile.rie
126+
@echo "Setting up containerized test runner..."
127+
@if [ ! -d ".test-runner" ]; then \
128+
echo "Cloning containerized-test-runner-for-aws-lambda..."; \
129+
git clone --quiet https://github.com/aws/containerized-test-runner-for-aws-lambda.git .test-runner; \
130+
fi
131+
@echo "Building test runner Docker image..."
132+
@docker build -t test-runner:local -f Dockerfile.test-runner .
133+
@echo "Running tests in Docker..."
134+
@echo "Running actual tests..."
135+
@docker run --rm \
136+
-e DOCKER_API_VERSION=1.44 \
137+
-v /var/run/docker.sock:/var/run/docker.sock \
138+
-v "$(CURDIR)/dockerized-tests:/tests:ro" \
139+
test-runner:local \
140+
--test-image local/test \
141+
--debug \
142+
/tests/*.json
143+
122144
test-rie:
123145
./scripts/test-rie.sh
124146

125147
nuke:
126148
docker kill $$(docker ps -q)
127149

128-
129150
# Run RIE in Lambda Managed Instance (LMI) mode with concurrent polling.
130151
test-rie-lmi:
131152
RIE_MAX_CONCURRENCY=$(RIE_MAX_CONCURRENCY) ./scripts/test-rie.sh $(EXAMPLE)

dockerized-tests/core.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"tests": [
3+
{
4+
"name": "test_echo",
5+
"handler": "basic-lambda",
6+
"request": {
7+
"command": "test"
8+
},
9+
"assertions": [
10+
{
11+
"response": {
12+
"msg": "Command test executed."
13+
},
14+
"transform": "{msg: .msg}"
15+
}
16+
]
17+
}
18+
]
19+
}

0 commit comments

Comments
 (0)