-
Notifications
You must be signed in to change notification settings - Fork 95
fix awscli patch for new create_nested_client, introduce bats tests #93
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
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
|
|
@@ -3,3 +3,6 @@ | |
| *.egg-info/ | ||
| *.pyc | ||
| __pycache__/ | ||
| /.idea/ | ||
| /output/* | ||
| !/output/.gitkeep | ||
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
Empty file.
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,57 @@ | ||
| # BATS tests | ||
|
|
||
| The tests in this folder are not regular Pytest tests. | ||
| They are implemented with [BATS](https://github.com/bats-core/bats-core) to test `awslocal` from `bash`. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| **Install BATS**: If you don't have BATS installed, you need to install it first. On a Unix-like system, you can usually install it using a package manager. | ||
|
|
||
| For any system with `npm`: | ||
| ```bash | ||
| npm install -g bats | ||
| ``` | ||
|
|
||
| For macOS using Homebrew: | ||
| ```bash | ||
| brew install bats-core | ||
| ``` | ||
|
|
||
| Alternatively, you can install BATS manually by cloning the repository and adding the `bin` folder to your `PATH` environment variable. | ||
| ```bash | ||
| git clone https://github.com/bats-core/bats-core.git | ||
| cd bats-core | ||
| sudo ./install.sh /usr/local | ||
| ``` | ||
|
|
||
| ## Writing tests | ||
|
|
||
| Create a file with a `.bats` extension, for example, `test_example.bats`. Here’s a simple test file: | ||
|
|
||
| ```bash | ||
| #!/usr/bin/env bats | ||
| @test "test description" { | ||
| run echo "hello" | ||
| [ "$status" -eq 0 ] | ||
| [ "$output" = "hello" ] | ||
| } | ||
| ``` | ||
|
|
||
| ## Running Tests | ||
| To run the tests, execute the bats command followed by the test file or directory containing test files: | ||
|
|
||
| ```bash | ||
| bats test_example.bats | ||
| ``` | ||
|
|
||
| You can also run all `.bats` files in a directory: | ||
|
|
||
| ```bash | ||
| bats tests/bin | ||
| ``` | ||
|
|
||
| To run with some debug information, you can use this: | ||
|
|
||
| ```bash | ||
| bats --trace --verbose-run --print-output-on-failure -r tests/bin/ | ||
| ``` |
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,4 @@ | ||
| { | ||
| "name": "test-lambda", | ||
| "version": "0.0.1" | ||
| } |
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 @@ | ||
| exports.handler = async (event, context) => { return "Pong!" }; |
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,19 @@ | ||
| AWSTemplateFormatVersion: '2010-09-09' | ||
| Transform: AWS::Serverless-2016-10-31 | ||
| Resources: | ||
| TestLambda: | ||
| Type: AWS::Serverless::Function | ||
| Properties: | ||
| FunctionName: TestLambda | ||
| CodeUri: TestLambda | ||
| Handler: src/app.handler | ||
| Runtime: nodejs22.x | ||
| TestLambdaUrl: | ||
| Type: AWS::Lambda::Url | ||
| Properties: | ||
| TargetFunctionArn: !GetAtt TestLambda.Arn | ||
| AuthType: NONE | ||
| Outputs: | ||
| LambdaURL: | ||
| Description: URL for the Lambda | ||
| Value: !GetAtt TestLambdaUrl.FunctionUrl |
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,27 @@ | ||
| #!/usr/bin/env bats | ||
|
|
||
| setup_file() { | ||
| # Ensure the AWS CLI is configured to use LocalStack | ||
| export AWS_ACCESS_KEY_ID=test | ||
| export AWS_SECRET_ACCESS_KEY=test | ||
| export AWS_DEFAULT_REGION=us-east-1 | ||
|
|
||
| # Create a bucket for the test | ||
| awslocal s3 mb s3://cfn-package-lambdas | ||
| } | ||
|
|
||
| @test "cloudformation package, deploy, execute" { | ||
| # Package the template | ||
| run awslocal cloudformation package --template $BATS_TEST_DIRNAME/cfn_templates/lamba/template.yaml --output-template output/packaged_template.yaml --s3-bucket cfn-package-lambdas | ||
| [ "$status" -eq 0 ] | ||
| run awslocal cloudformation deploy --template-file output/packaged_template.yaml --stack-name test-stack | ||
| [ "$status" -eq 0 ] | ||
| URL=`awslocal cloudformation describe-stacks --stack-name test-stack --query "Stacks[0].Outputs[?OutputKey=='LambdaURL'].OutputValue" --output text` | ||
| curl -s $URL | grep "Pong!" | ||
| [ "$status" -eq 0 ] | ||
| } | ||
|
|
||
| teardown_file() { | ||
| awslocal cloudformation delete-stack --stack-name test-stack | ||
| awslocal s3 rb s3://cfn-package-lambdas --force | ||
| } |
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,23 @@ | ||
| #!/usr/bin/env bats | ||
|
|
||
| setup_file() { | ||
| # Ensure the AWS CLI is configured to use LocalStack | ||
| export AWS_ACCESS_KEY_ID=test | ||
| export AWS_SECRET_ACCESS_KEY=test | ||
| export AWS_DEFAULT_REGION=us-east-1 | ||
| } | ||
|
|
||
| @test "lambda list-functions" { | ||
| run awslocal lambda list-functions | ||
| [ "$status" -eq 0 ] | ||
| } | ||
|
|
||
| @test "s3api list-buckets" { | ||
| run awslocal s3api list-buckets | ||
| [ "$status" -eq 0 ] | ||
| } | ||
|
|
||
| @test "s3 ls" { | ||
| run awslocal s3api list-buckets | ||
| [ "$status" -eq 0 ] | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.