Skip to content

Commit 4e58179

Browse files
committed
feat: add subset of tests
1 parent 1ddf3e5 commit 4e58179

File tree

5 files changed

+222
-1
lines changed

5 files changed

+222
-1
lines changed

.github/workflows/dockerized-test.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
branches: [ '*' ]
88

99
jobs:
10-
build:
10+
dockerized-test:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
@@ -27,3 +27,10 @@ jobs:
2727

2828
- name: Build the image
2929
run: docker build . -t local/test -f Dockerfile.test --build-arg BASE_IMAGE=public.ecr.aws/lambda/ruby:${{ matrix.ruby_version }}
30+
31+
- name: Run tests
32+
uses: aws/containerized-test-runner-for-aws-lambda@v1
33+
with:
34+
suiteFileArray: ["./test/dockerized/suites/*.json"]
35+
dockerImageName: local/test
36+
taskFolder: ./test/dockerized/tasks

test/dockerized/suites/core.json

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
"tests": [
3+
{
4+
"name": "test_echo",
5+
"handler": "core.ping",
6+
"request": {
7+
"msg": "message"
8+
},
9+
"assertions": [
10+
{
11+
"response": {
12+
"msg": "pong[message]"
13+
}
14+
}
15+
]
16+
},
17+
{
18+
"name": "test_string_payload",
19+
"handler": "core.str_ping",
20+
"request": "message",
21+
"assertions": [
22+
{
23+
"response": {
24+
"msg": "pong[message]"
25+
}
26+
}
27+
]
28+
},
29+
{
30+
"name": "test_module_echo",
31+
"handler": "core.HandlerClass.ping",
32+
"request": {
33+
"msg": "MyMessage"
34+
},
35+
"assertions": [
36+
{
37+
"response": "Module Message: 'MyMessage'"
38+
}
39+
]
40+
},
41+
{
42+
"name": "test_deep_module_echo",
43+
"handler": "core.DeepModule::Handler.ping",
44+
"request": {
45+
"msg": "MyMessage"
46+
},
47+
"assertions": [
48+
{
49+
"response": "Deep Module Message: 'MyMessage'"
50+
}
51+
]
52+
},
53+
{
54+
"name": "test_error",
55+
"handler": "core.broken",
56+
"request": {
57+
"msg": "message"
58+
},
59+
"assertions": [
60+
{
61+
"errorType": "Function<ArgumentError>"
62+
}
63+
]
64+
},
65+
{
66+
"name": "test_string",
67+
"handler": "core.string",
68+
"request": {
69+
"msg": "MyMessage"
70+
},
71+
"assertions": [
72+
{
73+
"response": "Message: 'MyMessage'"
74+
}
75+
]
76+
}
77+
]
78+
}

test/dockerized/suites/ctx.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"tests": [
3+
{
4+
"name": "test_ctx_cognito_pool_id",
5+
"handler": "ctx.get_cognito_pool_id",
6+
"cognitoIdentity": {
7+
"cognitoIdentityId": "4ab95ea510c14353a7f6da04489c43b8",
8+
"cognitoIdentityPoolId": "35ab4794a79a4f23947d3e851d3d6578"
9+
},
10+
"request": {},
11+
"assertions": [
12+
{
13+
"response": {
14+
"cognito_pool_id": "35ab4794a79a4f23947d3e851d3d6578"
15+
}
16+
}
17+
]
18+
},
19+
{
20+
"name": "test_ctx_cognito_identity_id",
21+
"handler": "ctx.get_cognito_identity_id",
22+
"cognitoIdentity": {
23+
"cognitoIdentityId": "4ab95ea510c14353a7f6da04489c43b8",
24+
"cognitoIdentityPoolId": "35ab4794a79a4f23947d3e851d3d6578"
25+
},
26+
"request": {},
27+
"assertions": [
28+
{
29+
"response": {
30+
"cognito_identity_id": "4ab95ea510c14353a7f6da04489c43b8"
31+
}
32+
}
33+
]
34+
},
35+
{
36+
"name": "get_remaining_time_in_millis | elapsedTime",
37+
"handler": "ctx.get_remaining_time_from_context",
38+
"request": {
39+
"sleepTimeSeconds": 0.1
40+
},
41+
"assertions": [
42+
{
43+
"transform": ".elapsedTime >= 100",
44+
"response": true
45+
}
46+
]
47+
}
48+
]
49+
}

test/dockerized/tasks/core.rb

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
3+
def ping(event:, context:)
4+
resp = {}
5+
if event.nil?
6+
resp[:event_nil] = true
7+
else
8+
resp[:msg] = "pong[#{event["msg"]}]"
9+
end
10+
puts "Hello, loggers!"
11+
resp
12+
end
13+
14+
def str_ping(event:, context:)
15+
{ msg: "pong[#{event}]" }
16+
end
17+
18+
def broken(_)
19+
raise ArgumentError.new("My error message.")
20+
end
21+
22+
def string(event:, context:)
23+
"Message: '#{event["msg"]}'"
24+
end
25+
26+
def curl(event:,context:)
27+
resp = Net::HTTP.get(URI(event["url"]))
28+
if resp.size > 0
29+
{ success: true }
30+
else
31+
raise "Empty response!"
32+
end
33+
end
34+
35+
def io(_)
36+
StringIO.new("This is IO!")
37+
end
38+
39+
def execution_env(_)
40+
{ "AWS_EXECUTION_ENV" => ENV["AWS_EXECUTION_ENV"] }
41+
end
42+
43+
class HandlerClass
44+
def self.ping(event:,context:)
45+
"Module Message: '#{event["msg"]}'"
46+
end
47+
end
48+
49+
module DeepModule
50+
class Handler
51+
def self.ping(event:,context:)
52+
"Deep Module Message: '#{event["msg"]}'"
53+
end
54+
end
55+
end

test/dockerized/tasks/cxt.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
3+
def get_context(event:,context:)
4+
{
5+
function_name: context.function_name,
6+
deadline_ns: context.deadline_ns,
7+
aws_request_id: context.aws_request_id,
8+
invoked_function_arn: context.invoked_function_arn,
9+
log_group_name: context.log_group_name,
10+
log_stream_name: context.log_stream_name,
11+
memory_limit_in_mb: context.memory_limit_in_mb,
12+
function_version: context.function_version
13+
}
14+
end
15+
16+
def get_cognito_pool_id(event:,context:)
17+
{ cognito_pool_id: context.identity["cognitoIdentityPoolId"]}
18+
end
19+
20+
def get_cognito_identity_id(event:,context:)
21+
{ cognito_identity_id: context.identity["cognitoIdentityId"] }
22+
end
23+
24+
def echo_context(event:,context:)
25+
context.client_context
26+
end
27+
28+
def get_remaining_time_from_context(event:, context:)
29+
before = context.get_remaining_time_in_millis()
30+
sleep(event['sleepTimeSeconds'])
31+
return { elapsedTime: before - context.get_remaining_time_in_millis() }
32+
end

0 commit comments

Comments
 (0)