From 96509f7da86f9a0b566f2e440d9092fe850cc4b2 Mon Sep 17 00:00:00 2001 From: Maxime David Date: Fri, 25 Apr 2025 10:19:41 +0000 Subject: [PATCH 01/14] feat: add Dockerized testing --- .gitignore | 2 ++ Dockerfile.test | 6 ++++++ 2 files changed, 8 insertions(+) create mode 100644 Dockerfile.test diff --git a/.gitignore b/.gitignore index f6b393d..1e84ce6 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ test/examples/hello-world-docker/pkg *.iml .DS_Store Gemfile.lock +# useful when using rbenv +.ruby-version diff --git a/Dockerfile.test b/Dockerfile.test new file mode 100644 index 0000000..8aae032 --- /dev/null +++ b/Dockerfile.test @@ -0,0 +1,6 @@ +FROM public.ecr.aws/lambda/ruby:3.3 +ENV GEM_HOME=/var/runtime +RUN gem uninstall aws_lambda_ric --executables +ADD pkg /tmp/pkg +RUN gem install /tmp/pkg/aws_lambda_ric-*.gem +RUN rm -rf /tmp/pkg \ No newline at end of file From 71d10627ee6abd5a11cdf686aaeca8c1888c14ac Mon Sep 17 00:00:00 2001 From: Maxime David Date: Fri, 25 Apr 2025 10:48:12 +0000 Subject: [PATCH 02/14] feat: add new GitHub action workflow --- .github/workflows/dockerized-test.yml | 25 +++++++++++++++++++++++++ Dockerfile.test | 3 ++- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/dockerized-test.yml diff --git a/.github/workflows/dockerized-test.yml b/.github/workflows/dockerized-test.yml new file mode 100644 index 0000000..353a1a0 --- /dev/null +++ b/.github/workflows/dockerized-test.yml @@ -0,0 +1,25 @@ +name: dockerized-test + +on: + push: + branches: [ main ] + pull_request: + branches: [ '*' ] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + ruby_version: ['3.1', '3.2', '3.3'] + + steps: + - uses: actions/checkout@v3 + - name: Set up ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby_version }} + - name: Build the lib + run: make build + - name: Build the image + run: docker build . -t local/test -f Dockerfile.test --build-arg BASE_IMAGE=public.ecr.aws/lambda/ruby:${{ matrix.ruby_version }} diff --git a/Dockerfile.test b/Dockerfile.test index 8aae032..b59aafb 100644 --- a/Dockerfile.test +++ b/Dockerfile.test @@ -1,4 +1,5 @@ -FROM public.ecr.aws/lambda/ruby:3.3 +ARG BASE_IMAGE +FROM $BASE_IMAGE ENV GEM_HOME=/var/runtime RUN gem uninstall aws_lambda_ric --executables ADD pkg /tmp/pkg From a96c50954877f3f10e1cd88c99f5bc2b1b373d33 Mon Sep 17 00:00:00 2001 From: Maxime David Date: Fri, 25 Apr 2025 10:51:00 +0000 Subject: [PATCH 03/14] feat: add new GitHub action workflow --- .github/workflows/dockerized-test.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/dockerized-test.yml b/.github/workflows/dockerized-test.yml index 353a1a0..ba06b72 100644 --- a/.github/workflows/dockerized-test.yml +++ b/.github/workflows/dockerized-test.yml @@ -12,14 +12,18 @@ jobs: strategy: matrix: ruby_version: ['3.1', '3.2', '3.3'] + fail-fast: false steps: - uses: actions/checkout@v3 + - name: Set up ruby uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby_version }} + - name: Build the lib run: make build + - name: Build the image run: docker build . -t local/test -f Dockerfile.test --build-arg BASE_IMAGE=public.ecr.aws/lambda/ruby:${{ matrix.ruby_version }} From b3a4a88142909d8a467eb4ff811e770a07f023da Mon Sep 17 00:00:00 2001 From: Maxime David Date: Fri, 25 Apr 2025 10:52:16 +0000 Subject: [PATCH 04/14] feat: add new GitHub action workflow --- .github/workflows/dockerized-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dockerized-test.yml b/.github/workflows/dockerized-test.yml index ba06b72..57c02d4 100644 --- a/.github/workflows/dockerized-test.yml +++ b/.github/workflows/dockerized-test.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - ruby_version: ['3.1', '3.2', '3.3'] + ruby_version: ['3.2', '3.3', '3.4'] fail-fast: false steps: From 1ddf3e5783e3171499961834088dccc7fc3e9ef5 Mon Sep 17 00:00:00 2001 From: Maxime David Date: Fri, 25 Apr 2025 10:53:26 +0000 Subject: [PATCH 05/14] feat: add new GitHub action workflow --- .github/workflows/dockerized-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dockerized-test.yml b/.github/workflows/dockerized-test.yml index 57c02d4..20b228f 100644 --- a/.github/workflows/dockerized-test.yml +++ b/.github/workflows/dockerized-test.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - ruby_version: ['3.2', '3.3', '3.4'] + ruby_version: ['3.3', '3.4'] fail-fast: false steps: From 4e58179c4db3faa6cde77c1ee5cca58061467cc8 Mon Sep 17 00:00:00 2001 From: Maxime David Date: Fri, 25 Apr 2025 11:35:02 +0000 Subject: [PATCH 06/14] feat: add subset of tests --- .github/workflows/dockerized-test.yml | 9 +++- test/dockerized/suites/core.json | 78 +++++++++++++++++++++++++++ test/dockerized/suites/ctx.json | 49 +++++++++++++++++ test/dockerized/tasks/core.rb | 55 +++++++++++++++++++ test/dockerized/tasks/cxt.rb | 32 +++++++++++ 5 files changed, 222 insertions(+), 1 deletion(-) create mode 100644 test/dockerized/suites/core.json create mode 100644 test/dockerized/suites/ctx.json create mode 100644 test/dockerized/tasks/core.rb create mode 100644 test/dockerized/tasks/cxt.rb diff --git a/.github/workflows/dockerized-test.yml b/.github/workflows/dockerized-test.yml index 20b228f..41b02bb 100644 --- a/.github/workflows/dockerized-test.yml +++ b/.github/workflows/dockerized-test.yml @@ -7,7 +7,7 @@ on: branches: [ '*' ] jobs: - build: + dockerized-test: runs-on: ubuntu-latest strategy: matrix: @@ -27,3 +27,10 @@ jobs: - name: Build the image run: docker build . -t local/test -f Dockerfile.test --build-arg BASE_IMAGE=public.ecr.aws/lambda/ruby:${{ matrix.ruby_version }} + + - name: Run tests + uses: aws/containerized-test-runner-for-aws-lambda@v1 + with: + suiteFileArray: ["./test/dockerized/suites/*.json"] + dockerImageName: local/test + taskFolder: ./test/dockerized/tasks diff --git a/test/dockerized/suites/core.json b/test/dockerized/suites/core.json new file mode 100644 index 0000000..20e8149 --- /dev/null +++ b/test/dockerized/suites/core.json @@ -0,0 +1,78 @@ +{ + "tests": [ + { + "name": "test_echo", + "handler": "core.ping", + "request": { + "msg": "message" + }, + "assertions": [ + { + "response": { + "msg": "pong[message]" + } + } + ] + }, + { + "name": "test_string_payload", + "handler": "core.str_ping", + "request": "message", + "assertions": [ + { + "response": { + "msg": "pong[message]" + } + } + ] + }, + { + "name": "test_module_echo", + "handler": "core.HandlerClass.ping", + "request": { + "msg": "MyMessage" + }, + "assertions": [ + { + "response": "Module Message: 'MyMessage'" + } + ] + }, + { + "name": "test_deep_module_echo", + "handler": "core.DeepModule::Handler.ping", + "request": { + "msg": "MyMessage" + }, + "assertions": [ + { + "response": "Deep Module Message: 'MyMessage'" + } + ] + }, + { + "name": "test_error", + "handler": "core.broken", + "request": { + "msg": "message" + }, + "assertions": [ + { + "errorType": "Function" + } + ] + }, + { + "name": "test_string", + "handler": "core.string", + "request": { + "msg": "MyMessage" + }, + "assertions": [ + { + "response": "Message: 'MyMessage'" + } + ] + } + ] +} \ No newline at end of file diff --git a/test/dockerized/suites/ctx.json b/test/dockerized/suites/ctx.json new file mode 100644 index 0000000..86b9099 --- /dev/null +++ b/test/dockerized/suites/ctx.json @@ -0,0 +1,49 @@ +{ + "tests": [ + { + "name": "test_ctx_cognito_pool_id", + "handler": "ctx.get_cognito_pool_id", + "cognitoIdentity": { + "cognitoIdentityId": "4ab95ea510c14353a7f6da04489c43b8", + "cognitoIdentityPoolId": "35ab4794a79a4f23947d3e851d3d6578" + }, + "request": {}, + "assertions": [ + { + "response": { + "cognito_pool_id": "35ab4794a79a4f23947d3e851d3d6578" + } + } + ] + }, + { + "name": "test_ctx_cognito_identity_id", + "handler": "ctx.get_cognito_identity_id", + "cognitoIdentity": { + "cognitoIdentityId": "4ab95ea510c14353a7f6da04489c43b8", + "cognitoIdentityPoolId": "35ab4794a79a4f23947d3e851d3d6578" + }, + "request": {}, + "assertions": [ + { + "response": { + "cognito_identity_id": "4ab95ea510c14353a7f6da04489c43b8" + } + } + ] + }, + { + "name": "get_remaining_time_in_millis | elapsedTime", + "handler": "ctx.get_remaining_time_from_context", + "request": { + "sleepTimeSeconds": 0.1 + }, + "assertions": [ + { + "transform": ".elapsedTime >= 100", + "response": true + } + ] + } + ] +} \ No newline at end of file diff --git a/test/dockerized/tasks/core.rb b/test/dockerized/tasks/core.rb new file mode 100644 index 0000000..85e53e8 --- /dev/null +++ b/test/dockerized/tasks/core.rb @@ -0,0 +1,55 @@ +# Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. + +def ping(event:, context:) + resp = {} + if event.nil? + resp[:event_nil] = true + else + resp[:msg] = "pong[#{event["msg"]}]" + end + puts "Hello, loggers!" + resp + end + + def str_ping(event:, context:) + { msg: "pong[#{event}]" } + end + + def broken(_) + raise ArgumentError.new("My error message.") + end + + def string(event:, context:) + "Message: '#{event["msg"]}'" + end + + def curl(event:,context:) + resp = Net::HTTP.get(URI(event["url"])) + if resp.size > 0 + { success: true } + else + raise "Empty response!" + end + end + + def io(_) + StringIO.new("This is IO!") + end + + def execution_env(_) + { "AWS_EXECUTION_ENV" => ENV["AWS_EXECUTION_ENV"] } + end + + class HandlerClass + def self.ping(event:,context:) + "Module Message: '#{event["msg"]}'" + end + end + + module DeepModule + class Handler + def self.ping(event:,context:) + "Deep Module Message: '#{event["msg"]}'" + end + end + end \ No newline at end of file diff --git a/test/dockerized/tasks/cxt.rb b/test/dockerized/tasks/cxt.rb new file mode 100644 index 0000000..072a573 --- /dev/null +++ b/test/dockerized/tasks/cxt.rb @@ -0,0 +1,32 @@ +# Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. + +def get_context(event:,context:) + { + function_name: context.function_name, + deadline_ns: context.deadline_ns, + aws_request_id: context.aws_request_id, + invoked_function_arn: context.invoked_function_arn, + log_group_name: context.log_group_name, + log_stream_name: context.log_stream_name, + memory_limit_in_mb: context.memory_limit_in_mb, + function_version: context.function_version + } + end + + def get_cognito_pool_id(event:,context:) + { cognito_pool_id: context.identity["cognitoIdentityPoolId"]} + end + + def get_cognito_identity_id(event:,context:) + { cognito_identity_id: context.identity["cognitoIdentityId"] } + end + + def echo_context(event:,context:) + context.client_context + end + + def get_remaining_time_from_context(event:, context:) + before = context.get_remaining_time_in_millis() + sleep(event['sleepTimeSeconds']) + return { elapsedTime: before - context.get_remaining_time_in_millis() } + end \ No newline at end of file From 3e50d3beee4f478dfc3b968cb4db81a356b24f46 Mon Sep 17 00:00:00 2001 From: Maxime David Date: Fri, 25 Apr 2025 11:37:12 +0000 Subject: [PATCH 07/14] feat: add subset of tests --- .github/workflows/dockerized-test.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dockerized-test.yml b/.github/workflows/dockerized-test.yml index 41b02bb..176e3db 100644 --- a/.github/workflows/dockerized-test.yml +++ b/.github/workflows/dockerized-test.yml @@ -31,6 +31,6 @@ jobs: - name: Run tests uses: aws/containerized-test-runner-for-aws-lambda@v1 with: - suiteFileArray: ["./test/dockerized/suites/*.json"] - dockerImageName: local/test - taskFolder: ./test/dockerized/tasks + suiteFileArray: '["./test/dockerized/suites/*.json"]' + dockerImageName: 'local/test' + taskFolder: './test/dockerized/tasks' From 025d79bd77e006a70554aaea50546d0ec10629f2 Mon Sep 17 00:00:00 2001 From: Maxime David Date: Fri, 25 Apr 2025 11:41:50 +0000 Subject: [PATCH 08/14] fix: action name --- .github/workflows/dockerized-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dockerized-test.yml b/.github/workflows/dockerized-test.yml index 176e3db..b52d7e1 100644 --- a/.github/workflows/dockerized-test.yml +++ b/.github/workflows/dockerized-test.yml @@ -29,7 +29,7 @@ jobs: run: docker build . -t local/test -f Dockerfile.test --build-arg BASE_IMAGE=public.ecr.aws/lambda/ruby:${{ matrix.ruby_version }} - name: Run tests - uses: aws/containerized-test-runner-for-aws-lambda@v1 + uses: aws/containerized-test-runner-for-aws-lambda with: suiteFileArray: '["./test/dockerized/suites/*.json"]' dockerImageName: 'local/test' From 0fa1c4d201a3384cacfe5ad80f879ada0412140a Mon Sep 17 00:00:00 2001 From: Maxime David Date: Fri, 25 Apr 2025 11:42:36 +0000 Subject: [PATCH 09/14] fix: action name --- .github/workflows/dockerized-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dockerized-test.yml b/.github/workflows/dockerized-test.yml index b52d7e1..0e1b221 100644 --- a/.github/workflows/dockerized-test.yml +++ b/.github/workflows/dockerized-test.yml @@ -29,7 +29,7 @@ jobs: run: docker build . -t local/test -f Dockerfile.test --build-arg BASE_IMAGE=public.ecr.aws/lambda/ruby:${{ matrix.ruby_version }} - name: Run tests - uses: aws/containerized-test-runner-for-aws-lambda + uses: aws/containerized-test-runner-for-aws-lambda@maxday/init with: suiteFileArray: '["./test/dockerized/suites/*.json"]' dockerImageName: 'local/test' From bb00157bade0abf2a08777ca5554d5aa19bbc68c Mon Sep 17 00:00:00 2001 From: Maxime David Date: Fri, 25 Apr 2025 12:38:54 +0000 Subject: [PATCH 10/14] fix: GitHub actions --- .github/workflows/dockerized-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dockerized-test.yml b/.github/workflows/dockerized-test.yml index 0e1b221..fb485b1 100644 --- a/.github/workflows/dockerized-test.yml +++ b/.github/workflows/dockerized-test.yml @@ -10,9 +10,9 @@ jobs: dockerized-test: runs-on: ubuntu-latest strategy: + fail-fast: false matrix: ruby_version: ['3.3', '3.4'] - fail-fast: false steps: - uses: actions/checkout@v3 From 0a0d0095d34d50692baba636566e7cdec7e94f8f Mon Sep 17 00:00:00 2001 From: Maxime David Date: Fri, 25 Apr 2025 12:41:53 +0000 Subject: [PATCH 11/14] fix: GitHub actions --- .github/workflows/dockerized-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dockerized-test.yml b/.github/workflows/dockerized-test.yml index fb485b1..be89289 100644 --- a/.github/workflows/dockerized-test.yml +++ b/.github/workflows/dockerized-test.yml @@ -29,7 +29,7 @@ jobs: run: docker build . -t local/test -f Dockerfile.test --build-arg BASE_IMAGE=public.ecr.aws/lambda/ruby:${{ matrix.ruby_version }} - name: Run tests - uses: aws/containerized-test-runner-for-aws-lambda@maxday/init + uses: aws/containerized-test-runner-for-aws-lambda@c03e315c252d8ebc1c33c47975377d7c770db72c with: suiteFileArray: '["./test/dockerized/suites/*.json"]' dockerImageName: 'local/test' From bd2d027a98971aadc9c60b14a617f0601dc34d6f Mon Sep 17 00:00:00 2001 From: Maxime David Date: Fri, 25 Apr 2025 12:43:51 +0000 Subject: [PATCH 12/14] fix: GitHub actions --- .github/workflows/dockerized-test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/dockerized-test.yml b/.github/workflows/dockerized-test.yml index be89289..3a9cadd 100644 --- a/.github/workflows/dockerized-test.yml +++ b/.github/workflows/dockerized-test.yml @@ -5,6 +5,8 @@ on: branches: [ main ] pull_request: branches: [ '*' ] + workflow_dispatch: + jobs: dockerized-test: From d14b739e76f41720d32c614406f9959f8027cf4c Mon Sep 17 00:00:00 2001 From: Maxime David Date: Fri, 25 Apr 2025 14:33:17 +0000 Subject: [PATCH 13/14] fix: use main --- .github/workflows/dockerized-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dockerized-test.yml b/.github/workflows/dockerized-test.yml index 3a9cadd..30f6ed5 100644 --- a/.github/workflows/dockerized-test.yml +++ b/.github/workflows/dockerized-test.yml @@ -31,7 +31,7 @@ jobs: run: docker build . -t local/test -f Dockerfile.test --build-arg BASE_IMAGE=public.ecr.aws/lambda/ruby:${{ matrix.ruby_version }} - name: Run tests - uses: aws/containerized-test-runner-for-aws-lambda@c03e315c252d8ebc1c33c47975377d7c770db72c + uses: aws/containerized-test-runner-for-aws-lambda@main with: suiteFileArray: '["./test/dockerized/suites/*.json"]' dockerImageName: 'local/test' From c88fe64c84ba315f670cd5a2e195181d467a00a5 Mon Sep 17 00:00:00 2001 From: Maxime David Date: Fri, 25 Apr 2025 14:38:37 +0000 Subject: [PATCH 14/14] fix: bump version --- .github/workflows/dockerized-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dockerized-test.yml b/.github/workflows/dockerized-test.yml index 30f6ed5..fe90b9d 100644 --- a/.github/workflows/dockerized-test.yml +++ b/.github/workflows/dockerized-test.yml @@ -31,7 +31,7 @@ jobs: run: docker build . -t local/test -f Dockerfile.test --build-arg BASE_IMAGE=public.ecr.aws/lambda/ruby:${{ matrix.ruby_version }} - name: Run tests - uses: aws/containerized-test-runner-for-aws-lambda@main + uses: aws/containerized-test-runner-for-aws-lambda@v1 with: suiteFileArray: '["./test/dockerized/suites/*.json"]' dockerImageName: 'local/test'