Skip to content

Commit d6a8730

Browse files
committed
feat: add harness testing
1 parent 727954a commit d6a8730

5 files changed

Lines changed: 265 additions & 0 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: dockerized-test
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
push:
8+
branches: [nodejs24.x]
9+
pull_request:
10+
branches: ['*']
11+
workflow_dispatch:
12+
13+
jobs:
14+
dockerized-test:
15+
runs-on: ubuntu-latest
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
node_version: ['22', '24']
20+
steps:
21+
- uses: actions/checkout@v5
22+
23+
- name: Set up Node.js
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version: ${{ matrix.node_version }}
27+
cache: npm
28+
29+
- name: Install dependencies
30+
run: npm ci --ignore-scripts
31+
32+
- name: Build the RIC tarball
33+
# Produces build-artifacts/aws-lambda-ric-<version>.tgz, which
34+
# Dockerfile.test unpacks into /var/runtime in the test image.
35+
run: npm run build:container
36+
37+
- name: Build the test image
38+
run: |
39+
docker build . \
40+
-t local/test \
41+
-f Dockerfile.test \
42+
--build-arg BASE_IMAGE=public.ecr.aws/lambda/nodejs:${{ matrix.node_version }}
43+
44+
- name: Run dockerized suites
45+
uses: aws/containerized-test-runner-for-aws-lambda@511d270614f2c6b1613848db6dcf920a591c3c89 # main
46+
with:
47+
suiteFileArray: '["./test/dockerized/suites/*.json"]'
48+
dockerImageName: 'local/test'
49+
taskFolder: './test/dockerized/tasks'

‎Dockerfile.test‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
ARG BASE_IMAGE=public.ecr.aws/lambda/nodejs:24
5+
FROM $BASE_IMAGE
6+
7+
# Swap the RIC shipped in the base image for the one we just built.
8+
ADD build-artifacts/aws-lambda-ric-*.tgz /tmp/
9+
RUN mv /tmp/package/* /var/runtime/ && rm -rf /tmp/package
10+
11+
COPY test/dockerized/tasks /var/task/

‎test/dockerized/suites/ctx.json‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"tests": [
3+
{
4+
"name": "client_context_is_echoed_when_no_w3c_key",
5+
"handler": "w3c.echoClientContext",
6+
"request": {},
7+
"clientContext": {
8+
"custom": { "value": "hello" },
9+
"environment": { "stage": "beta" }
10+
},
11+
"assertions": [
12+
{
13+
"response": {
14+
"custom": { "value": "hello" },
15+
"environment": { "stage": "beta" }
16+
}
17+
}
18+
]
19+
},
20+
21+
{
22+
"name": "client_context_is_null_when_header_absent",
23+
"handler": "w3c.echoClientContext",
24+
"request": {},
25+
"assertions": [
26+
{ "response": null }
27+
]
28+
}
29+
]
30+
}

‎test/dockerized/suites/w3c.json‎

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
{
2+
"tests": [
3+
{
4+
"name": "w3c_is_a_function_on_context",
5+
"handler": "w3c.w3cIsFunction",
6+
"request": {},
7+
"assertions": [
8+
{ "response": { "isFunction": true } }
9+
]
10+
},
11+
12+
{
13+
"name": "w3c_returns_empty_when_no_client_context_header",
14+
"handler": "w3c.getW3c",
15+
"request": {},
16+
"assertions": [
17+
{ "response": {} }
18+
]
19+
},
20+
21+
{
22+
"name": "w3c_returns_empty_when_client_context_has_no_w3c_key",
23+
"handler": "w3c.getW3c",
24+
"request": {},
25+
"clientContext": {
26+
"custom": { "value": "test" }
27+
},
28+
"assertions": [
29+
{ "response": {} }
30+
]
31+
},
32+
33+
{
34+
"name": "w3c_returns_baggage_only",
35+
"handler": "w3c.getW3c",
36+
"request": {},
37+
"clientContext": {
38+
"w3c": { "baggage": "userId=alice" }
39+
},
40+
"assertions": [
41+
{ "response": { "baggage": "userId=alice" } }
42+
]
43+
},
44+
45+
{
46+
"name": "w3c_returns_all_three_allowlisted_fields",
47+
"handler": "w3c.getW3c",
48+
"request": {},
49+
"clientContext": {
50+
"w3c": {
51+
"traceparent": "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01",
52+
"tracestate": "rojo=00f067aa0ba902b7",
53+
"baggage": "userId=alice"
54+
}
55+
},
56+
"assertions": [
57+
{
58+
"response": {
59+
"traceparent": "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01",
60+
"tracestate": "rojo=00f067aa0ba902b7",
61+
"baggage": "userId=alice"
62+
}
63+
}
64+
]
65+
},
66+
67+
{
68+
"name": "w3c_allowlist_drops_non_allowlisted_keys",
69+
"handler": "w3c.getW3c",
70+
"request": {},
71+
"clientContext": {
72+
"w3c": {
73+
"baggage": "keep=me",
74+
"unknownField": "should-not-appear",
75+
"x-custom-trace": "should-not-appear"
76+
}
77+
},
78+
"assertions": [
79+
{ "response": { "baggage": "keep=me" } }
80+
]
81+
},
82+
83+
{
84+
"name": "w3c_drops_allowlisted_fields_with_non_string_values",
85+
"handler": "w3c.getW3c",
86+
"request": {},
87+
"clientContext": {
88+
"w3c": {
89+
"traceparent": 42,
90+
"tracestate": null,
91+
"baggage": { "nested": "no" }
92+
}
93+
},
94+
"assertions": [
95+
{ "response": {} }
96+
]
97+
},
98+
99+
{
100+
"name": "w3c_treats_non_object_as_empty",
101+
"handler": "w3c.getW3c",
102+
"request": {},
103+
"clientContext": {
104+
"w3c": "not-an-object"
105+
},
106+
"assertions": [
107+
{ "response": {} }
108+
]
109+
},
110+
111+
{
112+
"name": "w3c_treats_array_as_empty",
113+
"handler": "w3c.getW3c",
114+
"request": {},
115+
"clientContext": {
116+
"w3c": ["baggage=abc"]
117+
},
118+
"assertions": [
119+
{ "response": {} }
120+
]
121+
},
122+
123+
{
124+
"name": "w3c_strips_source_clientContext_w3c_after_construction",
125+
"handler": "w3c.getW3cAndSource",
126+
"request": {},
127+
"clientContext": {
128+
"custom": { "value": "test" },
129+
"w3c": {
130+
"traceparent": "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01",
131+
"baggage": "userId=alice"
132+
}
133+
},
134+
"assertions": [
135+
{
136+
"response": {
137+
"w3c": {
138+
"traceparent": "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01",
139+
"baggage": "userId=alice"
140+
},
141+
"clientContextIsDefined": true,
142+
"clientContextHasW3c": false,
143+
"clientContext": { "custom": { "value": "test" } }
144+
}
145+
}
146+
]
147+
}
148+
]
149+
}

‎test/dockerized/tasks/w3c.mjs‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
//
4+
5+
export const getW3c = async (_event, context) => {
6+
return context.w3c();
7+
};
8+
9+
export const getW3cAndSource = async (_event, context) => {
10+
const clientContext = context.clientContext;
11+
return {
12+
w3c: context.w3c(),
13+
clientContextIsDefined: clientContext !== undefined,
14+
clientContextHasW3c:
15+
clientContext !== undefined && "w3c" in clientContext,
16+
clientContext: clientContext ?? null,
17+
};
18+
};
19+
20+
export const echoClientContext = async (_event, context) => {
21+
return context.clientContext ?? null;
22+
};
23+
24+
export const w3cIsFunction = async (_event, context) => {
25+
return { isFunction: typeof context.w3c === "function" };
26+
};

0 commit comments

Comments
 (0)