Skip to content

Commit

Permalink
Merge pull request #59 from MarketSquare/samuelpcabral-test_localstac…
Browse files Browse the repository at this point in the history
…k_linux

test with localstack and github actions
  • Loading branch information
samuelpcabral authored Aug 22, 2024
2 parents 2f6f6e9 + 8b7eabd commit 0bb1b6f
Show file tree
Hide file tree
Showing 32 changed files with 473 additions and 550 deletions.
4 changes: 0 additions & 4 deletions .flake8

This file was deleted.

57 changes: 57 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Run LocalStack And Execute Keyword Tests

on:
push:
pull_request:

jobs:
run-localstack-and-robot:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker
uses: docker/setup-buildx-action@v3
- name: Install Docker Compose
run: |
sudo apt-get update
sudo apt-get install docker-compose -y
- name: Start Localstack docker
working-directory: ./localstack
run: |
docker-compose up -d
- name: Wait for LocalStack to be ready
run: sleep 10
- name: Set up Python 3.10
uses: actions/setup-python@v4
env:
ROBOT_TESTS_DIR: ${{ github.workspace }}/Tests
ROBOT_REPORTS_DIR: ${{ github.workspace }}/reports
with:
python-version: '3.10'
- name: Install Dependencies
working-directory: ./
run: pip install -r requirements.txt
- name: Run Robot Framework
run: robot -d ./reports ./tests/robot
- name: Upload test results
uses: actions/upload-artifact@v1
if: always()
with:
name: robot_reports
path: reports

generate-robot-report:
if: always()
needs: [ run-localstack-and-robot ]
runs-on: ubuntu-latest
steps:
- name: Download reports
uses: actions/download-artifact@v1
with:
name: robot_reports
- name: Send report to commit
uses: joonvena/robotframework-reporter-action@v2.4
with:
gh_access_token: ${{ secrets.GITHUB_TOKEN }}
report_path: /robot_reports
78 changes: 1 addition & 77 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ __pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
Expand All @@ -34,16 +31,6 @@ share/python-wheels/
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
Expand All @@ -57,79 +44,16 @@ coverage.xml
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
virtual_env/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

#Pycharm
.idea
tests/robot/local_tests.robot
Expand Down
9 changes: 0 additions & 9 deletions .pre-commit-config.yaml

This file was deleted.

25 changes: 0 additions & 25 deletions .travis.yml

This file was deleted.

125 changes: 48 additions & 77 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,113 +1,84 @@
# ***** UNDER CONSTRUCTION *****
# Development environment

Feel free to create issues for ideas for new functionality with other aws services

We are working to create an environment with tests in localstack https://github.com/localstack/localstack if you have
experience with this tool and time, any help will be appreciated.


## Contributing to RobotFramework-AWS

Thank you for considering contributing to a library for interacting with AWS Services in RobotFramework for Test Automation.

Let's go over setting up the development environment.
Thank you for considering contributing to a library for interacting with AWS services in RobotFramework
for test automation.

Setup virtualenvironment:
Configure your environment as desired, the requirements are in the requirements.txt file

```sh
python -m venv venv
pip install -r requirements.txt
```

activate
## Testing

```sh
source venv/bin/activate
```
### Localstack

install dependencies
For now, we have inside the folder localstack the docker compose file and in the init-aws.sh the commands to send
for localstack.

To start localstack just run inside localstack folder:
```sh
pip install -r requirements.txt
docker-compose up -d
```
Then you can use inside robot, the endpoint http://localhost:4566

set environment variables for aws as ACCESS_KEY and SECRET_KEY

install package development setup from root directory where setup.py is

```sh
pip install -e .
```
### Robot Framework

## TESTING
The tests suites are inside tests/robot folder

For every keyword or method created, will be followed with two different tests. Unit and Robot tests.
Located in the tests directory are separated tests by type unit/robot.
The common variables, keywords and libraries should be in common.resource file. The tests suites have the
aws module name like s3.robot or sqs.robot then we can run it separately.

Robot Tests will need a configuration file added to the root of robot/ for tests to run.
Any extra file like txt, json, csv or similar should be inside data folder.

`run_arguments.robot`
The robot files should import only the common.resource.

```robotframework
## SUITE NAME
--name AWS Library Testing
## SETTINGS
# tools must be in same directory as run_arguments.robot
--pythonpath ./AWSLibrary
--pythonpath .
# LOG LEVEL
# --loglevel DEBUG
--loglevel INFO
# put all logs into directory
--outputdir reports
# --timestampoutputs
--debugfile debug.log
*** Settings ***
Resource common.resource
Suite Setup Create Session And Set Endpoint
Suite Teardown Delete All Sessions
```

## VIRTUAL DISPLAY
-v USE_XVFB:True
All the libraries import should be in common.resource, as the suite setup. The import to AWSLibrary is relative to
project source, because then you can test the new keywords or changes just running locally the tests

## PROXY
-v USE_PROXY:False
-v PROXY_TYPE:socks
-v PROXY_HOST:localhost
-v PROXY_PORT:9999
```robotframework
*** Settings ***
Library ${CURDIR}/../../src/AWSLibrary
Library Collections
Library OperatingSystem
## VARIABLES
-v ACCESS_KEY:
-v SECRET_KEY:
testsuites/
*** Keywords ***
Create Session And Set Endpoint
Create Session With Keys ${REGION} ${ACCESS_KEY} ${SECRET_KEY}
SQS Set Endpoint Url http://localhost:4566 # Point to localstack sqs instance
S3 Set Endpoint Url http://localhost:4566 # Point to localstack s3 instance
```

## Local AWS Services with Localstack

To run with debug level all tests, from the main folder:
```sh
docker-compose up -d

robot -d log -L TRACE tests/robot
```

<http://localhost:8055/>

Make sure and add your aws credentials in the variables section.

Unit tests and Robot Tests are automated with tox. You can run tox to test your build before committing your changes

To run just one module, like s3:
```sh
tox
robot -d log -L TRACE tests/robot/s3.robot
# or
robot -d log -L TRACE -i s3 tests/robot
```

Upon pushing your branch. Tox will run and travis ci will run the reports
### TO-DO

Tox will grab the AWS environment variables that you set. which you can see in tox.ini

### Pre Commit

We use flake8 for checking for linting errors

Git Secrets will run on commit to make sure there are no hardcoded credentials in any files

Upon pushing your branch. Tox will run and travis ci will run the reports

### Issues

Feel free to create issues for ideas for new functionality with other aws services
- [x] Create CloudWatch and DynamoDB in localstack and create robot tests
- [x] Create GitHub actions to run the tests in push and merges.
- [ ] Add more services in library and in localstack
- [ ] Add robot tests for this new services
Loading

1 comment on commit 0bb1b6f

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
20 0 0 20 100 36.908552999s

Passed Tests

Name ⏱️ Duration Suite
Test Wait For Log 0.130 s Cloudwatch
Test Log Insights 30.070 s Cloudwatch
Test Put And Query Item 0.229 s Dynamo
Test Delete And Update Key 0.184 s Dynamo
Test Delete And Update Nested Key 0.079 s Dynamo
Test Delete Item 0.060 s Dynamo
Test Insert New Key 0.077 s Dynamo
Test Put And Query Item With Sort Key 0.083 s Dynamo
Test Delete And Update Key With Sort Key 0.130 s Dynamo
Test Upload And List 0.355 s S3
Test Upload And List With Folder 0.063 s S3
Test Remove And List With Prefix 0.064 s S3
Test Download 0.039 s S3
Test Get Content 0.033 s S3
Test Copy 0.055 s S3
Test Metadata 0.033 s S3
Send and Receive Message 0.109 s Sqs
Send and Receive Messages 0.080 s Sqs
Invalid Queue Name 0.010 s Sqs
Delete Messages 5.027 s Sqs

Please sign in to comment.