generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 34
feat: add dockerized testing #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+308
−0
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
96509f7
feat: add Dockerized testing
maxday 71d1062
feat: add new GitHub action workflow
maxday a96c509
feat: add new GitHub action workflow
maxday b3a4a88
feat: add new GitHub action workflow
maxday 1ddf3e5
feat: add new GitHub action workflow
maxday 4e58179
feat: add subset of tests
maxday 3e50d3b
feat: add subset of tests
maxday 025d79b
fix: action name
maxday 0fa1c4d
fix: action name
maxday bb00157
fix: GitHub actions
maxday 0a0d009
fix: GitHub actions
maxday bd2d027
fix: GitHub actions
maxday d14b739
fix: use main
maxday c88fe64
fix: bump version
maxday 8fac4ae
Merge branch 'main' into maxday/add-dockerized-testing
maxday acd7c37
feat: use harness tests locally
maxday 749c5c8
feat: clone the github action locally
maxday 38f40fa
feat: clone the github action locally
maxday ef8eec4
fix: docker
maxday 637e890
fix: tests
maxday 7da1fde
fix: disable ctx test for now
maxday f23baf4
fix: restrict token permissions
maxday 29411e7
fix: update dockerized-test.yml
maxday 4c285e2
fix: update dockerized-test.yml
maxday ad24de9
fix: update dockerized-test.yml
maxday aa41c2b
fix: use docker
maxday c438509
fix: path
maxday 16ac588
fix: docker
maxday bea0c50
feat: use docker
maxday 1332fe2
fix: harness
maxday 44d2fbf
fix: remove useless file
maxday 746515b
fix: using main
maxday a504b6a
fix: update readme
maxday File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| name: dockerized-test | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ main ] | ||
| pull_request: | ||
| branches: [ '*' ] | ||
| workflow_dispatch: | ||
|
|
||
|
|
||
| jobs: | ||
| dockerized-test: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| ruby_version: ['3.3', '3.4'] | ||
|
|
||
| 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 }} | ||
|
|
||
| - name: Run tests | ||
| uses: aws/containerized-test-runner-for-aws-lambda@main | ||
| with: | ||
| suiteFileArray: '["./test/dockerized/suites/*.json"]' | ||
| dockerImageName: 'local/test' | ||
| taskFolder: './test/dockerized/tasks' | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| ARG BASE_IMAGE | ||
| FROM $BASE_IMAGE | ||
| ENV GEM_HOME=/var/runtime | ||
| ADD test/dockerized/tasks /var/task | ||
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<ArgumentError>" | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "name": "test_string", | ||
| "handler": "core.string", | ||
| "request": { | ||
| "msg": "MyMessage" | ||
| }, | ||
| "assertions": [ | ||
| { | ||
| "response": "Message: 'MyMessage'" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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&.dig("cognitoIdentityPoolId")} | ||
| end | ||
|
|
||
| def get_cognito_identity_id(event:,context:) | ||
| { cognito_identity_id: context.identity&.dig("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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium
Copilot Autofix
AI 5 days ago
In general, you fix this issue by explicitly declaring a
permissions:block either at the top level of the workflow (applies to all jobs) or under the specific job, granting only the scopes needed (typicallycontents: readfor basic CI). Since this workflow only checks out code, sets up Ruby, builds, and runs tests, it appears to need only read access to repository contents, socontents: readis an appropriate minimal permission.The best fix without changing existing functionality is to add a root-level
permissions:block right after thename:(line 1) and before theon:block (line 3). This keeps the job definition intact and ensures any future jobs in this workflow inherit the same minimal permissions unless they override them. Concretely, in.github/workflows/dockerized-test.yml, insert:on new lines between current lines 1 and 3 (shifting the rest down). No additional methods, imports, or definitions are needed: this is a pure workflow configuration change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed