Skip to content

Testing Command lambda function with SQS queue #49

Testing Command lambda function with SQS queue

Testing Command lambda function with SQS queue #49

Workflow file for this run

name: "CI/CD Pipeline"
on:
push:
paths:
- "terraform/**"
- ".github/workflows/**"
branches:
- main
pull_request:
jobs:
linting:
name: "Lambda Functions (Linting)"
runs-on: ubuntu-latest
steps:
- name: Check out Git repository
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: 14
- name: "[Command Lambda Function] Install Dependencies & Run Linters"
working-directory: terraform/command_lambda_function
run: |
npm ci
npx eslint function.js
- name: "[Query Lambda Function] Install Dependencies & Run Linters"
working-directory: terraform/query_lambda_function
run: |
npm ci
npx eslint function.js
- name: "[Upsert Lambda Function] Install Dependencies & Run Linters"
working-directory: terraform/upsert_lambda_function
run: |
npm ci
npx eslint function.js
unit_tests:
name: "Lambda Functions (Unit Testing)"
runs-on: ubuntu-latest
steps:
- name: Check out Git repository
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: 14
- name: "[Command Lambda Function] Install Dependencies & Run Tests"
working-directory: terraform/command_lambda_function
run: |
npm ci
npm run test tests/
- name: "[Query Lambda Function] Install Dependencies & Run Tests"
working-directory: terraform/query_lambda_function
run: |
npm ci
npm run test tests/
- name: "[Upsert Lambda Function] Install Dependencies & Run Tests"
working-directory: terraform/upsert_lambda_function
run: |
npm ci
npm run test tests/
deployment:
needs: [linting, unit_tests]
if: contains(github.event.head_commit.message, '[deploy]')
name: "Deploy (Terraform -> AWS)"
runs-on: ubuntu-latest
outputs:
api_base_url: ${{steps.options.outputs.api_base_url}}
bucket_name: ${{steps.options.outputs.bucket_name}}
steps:
- name: Check out Git repository
uses: actions/checkout@v3
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
# terraform_version: 0.13.0:
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
terraform_wrapper: false
- name: Terraform Format
working-directory: terraform
run: terraform fmt -check
- name: Terraform Init
working-directory: terraform
run: terraform init
- name: Terraform Validate
working-directory: terraform
run: terraform validate -no-color
- name: Terraform Apply
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
working-directory: terraform
run: terraform apply -auto-approve -input=false
- name: Set Step's Output with `api_base_url_production` value from <terraform output>
id: api_base_url_step
working-directory: terraform
run: |
api_base_url=$(terraform output -raw api_base_url_production)
echo $api_base_url
echo "::set-output name=value::${api_base_url}"
- name: Set Job's Output with `api_base_url` value
uses: actions/github-script@v5
id: options
with:
script: |
console.log('*** api_base_url:', '${{steps.api_base_url_step.outputs.value}}');
core.setOutput('api_base_url', '${{steps.api_base_url_step.outputs.value}}');
integration_tests:
needs: deployment
name: "API Testing (Integration)"
runs-on: ubuntu-latest
steps:
- name: Check out Git repository
uses: actions/checkout@v3
- name: GET /urls Endpoint
working-directory: terraform/query_lambda_function/tests
run: |
api_base_url="${{ needs.deployment.outputs.api_base_url }}"
echo $api_base_url
bash integration.test.sh $api_base_url
- name: POST /urls Endpoint
working-directory: terraform/command_lambda_function/tests
run: |
api_base_url="${{ needs.deployment.outputs.api_base_url }}"
echo $api_base_url
bash integration.test.sh $api_base_url
load_tests:
needs: [deployment, integration_tests]
name: "API Testing (Load)"
runs-on: ubuntu-latest
container: artilleryio/artillery:latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Make reports directory
run: mkdir reports
- name: Execute load tests for GET /urls/{code} endpoint
env:
TARGET: "${{ needs.deployment.outputs.api_base_url }}"
run: /home/node/artillery/bin/run run --output reports/load_test_report_get_urls_endpoint.json terraform/query_lambda_function/tests/load_test.yaml
- name: Generate HTML report for GET /urls endpoint
run: /home/node/artillery/bin/run report --output reports/load_test_report_get_urls_endpoint.html reports/load_test_report_get_urls_endpoint.json
- name: Execute load tests for POST /urls endpoint
env:
TARGET: "${{ needs.deployment.outputs.api_base_url }}"
run: /home/node/artillery/bin/run run --output reports/load_test_report_post_urls_endpoint.json terraform/query_lambda_function/tests/load_test.yaml
- name: Generate HTML report for GET /urls endpoint
run: /home/node/artillery/bin/run report --output reports/load_test_report_post_urls_endpoint.html reports/load_test_report_post_urls_endpoint.json