Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
110 commits
Select commit Hold shift + click to select a range
1552ea6
set up integ test folder structure
mingkun2020 Nov 9, 2020
a890b7c
rename test_integ to tests_integ to keep it consistent with the unite…
mingkun2020 Nov 9, 2020
5a16b78
Added test-integ action to Makefile to launch integration tests
mgrandis Nov 10, 2020
582262c
Added all the single templates, fixed an error in basic_function.yaml
mgrandis Nov 10, 2020
5117bf6
Added test_basic_function.py from the POC, untouched; removed the "ex…
mgrandis Nov 10, 2020
c070cdc
Added basic api inline openapi test as a standalone file to be merged…
mgrandis Nov 10, 2020
243edc3
Renamed basic api inline openapi test with the test prefix
mgrandis Nov 10, 2020
8a9efd2
fix: Reverted to range instead of enumerate
mgrandis Nov 10, 2020
b35d912
set up basic code structure for sam integration test
mingkun2020 Nov 11, 2020
eb72ddd
Merge branch 'foss-integ-test' of https://github.com/mingkun2020/serv…
mingkun2020 Nov 11, 2020
0f79f4b
Updated helpers and expected basic_function file for the new verifica…
mgrandis Nov 12, 2020
090560b
add expected json file and fix some bugs
mingkun2020 Nov 12, 2020
f7ee968
remove unnecessary print statement
mingkun2020 Nov 12, 2020
2bde985
update basic function test
mingkun2020 Nov 12, 2020
65c2ebd
Added missing expected files, updated runner
mgrandis Nov 13, 2020
b763e7e
Removed the ResourceStatus check for each resource
mgrandis Nov 13, 2020
5a11d35
Refactored the test to inherit a BaseTest class, moved the basic_appl…
mgrandis Nov 13, 2020
a1f583e
add upload zip file and resolve uri with url feature, need refactorin…
mingkun2020 Nov 13, 2020
d12abf4
add extra test class and update yaml load call
mingkun2020 Nov 13, 2020
d8eb9ba
fix bug, now allow create bucket in multi regions
mingkun2020 Nov 14, 2020
083942c
Added random suffix to stack and bucket names to avoid name collisions
mgrandis Nov 14, 2020
e68b81e
refactor: Moved some stuff into methods in base_test, updated the Mak…
mgrandis Nov 16, 2020
4ae155d
chore: Black formatting
mgrandis Nov 16, 2020
4130f3d
set up integ test folder structure
mingkun2020 Nov 9, 2020
923934b
rename test_integ to tests_integ to keep it consistent with the unite…
mingkun2020 Nov 9, 2020
67c2674
Added test-integ action to Makefile to launch integration tests
mgrandis Nov 10, 2020
ee5402e
Added all the single templates, fixed an error in basic_function.yaml
mgrandis Nov 10, 2020
0faf6e4
Added test_basic_function.py from the POC, untouched; removed the "ex…
mgrandis Nov 10, 2020
dedd33b
set up basic code structure for sam integration test
mingkun2020 Nov 11, 2020
b4eb18d
Added basic api inline openapi test as a standalone file to be merged…
mgrandis Nov 10, 2020
f7fc08b
Renamed basic api inline openapi test with the test prefix
mgrandis Nov 10, 2020
0a96214
fix: Reverted to range instead of enumerate
mgrandis Nov 10, 2020
a88b80b
Updated helpers and expected basic_function file for the new verifica…
mgrandis Nov 12, 2020
65bb94a
add expected json file and fix some bugs
mingkun2020 Nov 12, 2020
6a9fd89
remove unnecessary print statement
mingkun2020 Nov 12, 2020
dd9bec1
update basic function test
mingkun2020 Nov 12, 2020
8c900d2
Added missing expected files, updated runner
mgrandis Nov 13, 2020
a5bfc51
Removed the ResourceStatus check for each resource
mgrandis Nov 13, 2020
bb016f5
Refactored the test to inherit a BaseTest class, moved the basic_appl…
mgrandis Nov 13, 2020
6c85d6d
add upload zip file and resolve uri with url feature, need refactorin…
mingkun2020 Nov 13, 2020
896ef40
add extra test class and update yaml load call
mingkun2020 Nov 13, 2020
b45a890
fix bug, now allow create bucket in multi regions
mingkun2020 Nov 14, 2020
ae775b7
Added random suffix to stack and bucket names to avoid name collisions
mgrandis Nov 14, 2020
b61a189
refactor: Moved some stuff into methods in base_test, updated the Mak…
mgrandis Nov 16, 2020
ff18eee
chore: Black formatting
mgrandis Nov 16, 2020
e7bdf6c
refactor: No more references to BaseTest, using cls and self instead
mgrandis Nov 18, 2020
c3037ae
fix bug for creating bucket in us-east-1
mingkun2020 Nov 18, 2020
17f3572
Merge branch 'foss-integ-test' of https://github.com/mingkun2020/serv…
mingkun2020 Nov 18, 2020
da61baf
update _upload_resources and _clean_bucket after resolving merge conf…
mingkun2020 Nov 18, 2020
dab73e7
refactor: In BaseTest, moved some stuff to class attributes, added doc
mgrandis Nov 18, 2020
3e3f387
refactor: Moved the resource file maps to their own py file, file_res…
mgrandis Nov 18, 2020
cf1d3f2
feat: Fully implemented basic_api test and various refactors
mgrandis Nov 18, 2020
e41d19d
refactor: Renamed S3 dict from URI to URL
mgrandis Nov 18, 2020
d37fda5
feat: Implemented all the test_basic_api tests, added get_stack_stage…
mgrandis Nov 19, 2020
befee0e
feat: test_basic_application tests migrated
mgrandis Nov 19, 2020
0fac1bc
feat: Migrated test_basic_http_api
mgrandis Nov 19, 2020
1bdb60b
feat: Migrated basic_state_machine tests
mgrandis Nov 20, 2020
e1bf1f8
migrate all basic function test
mingkun2020 Nov 20, 2020
09e9789
migrate all basic layer version test
mingkun2020 Nov 20, 2020
ba3d54d
remove useless import and add NoRegionError in create bucket when reg…
mingkun2020 Nov 20, 2020
914cb79
Merge branch 'foss-integ-test' of https://github.com/mingkun2020/serv…
mingkun2020 Nov 20, 2020
9a3b154
refactor: Added url type to FILE_TO_S3_URL_MAP so we don't rely on th…
mgrandis Nov 20, 2020
30e841e
refactor: Removed unnecessary parameter
mgrandis Nov 20, 2020
4eaaed0
docs: Added docstrings for basic tests
mgrandis Nov 20, 2020
2e14e38
remove unused import and update layer version test with parameters
mingkun2020 Nov 20, 2020
7c91bb0
black reformating
mingkun2020 Nov 20, 2020
20e3cfd
update appveyor.yml file
mingkun2020 Nov 20, 2020
4091d3f
fix: Changed string formatting incompatible with Python 2 in base_tes…
mgrandis Nov 20, 2020
c79c53b
add make test-integ in appveyor.yml file
mingkun2020 Nov 20, 2020
b6e227b
Merge branch 'foss-integ-test' of https://github.com/mingkun2020/serv…
mingkun2020 Nov 20, 2020
a2918f6
add default region in appveyor environment
mingkun2020 Nov 20, 2020
ef7acfe
fix: Reverting adding aws-sam-cli to dev dependencies, it's for integ…
mgrandis Nov 21, 2020
1c4c1c8
refactor: Changed a remaining python3 string format syntax in _fill_t…
mgrandis Nov 21, 2020
2857627
refactor: Using URI throughout, yaml load/dump function, [] not used …
mgrandis Nov 23, 2020
e099b0b
feat: Added local Deployer class so that we don't depend on sam-cli a…
mgrandis Nov 24, 2020
6a97509
fix appveyor os.mkdir failure
mingkun2020 Nov 24, 2020
453a1ca
revert changes in appveyor.yml, run make test-integ in the tox.ini
mingkun2020 Nov 24, 2020
2cb57a9
black reformat
mingkun2020 Nov 24, 2020
abcc4aa
refactor: Get resource default returned values are most consistent, a…
mgrandis Nov 25, 2020
f97d759
refactor: Renamed get_stack_stages functions to include api, removed …
mgrandis Nov 26, 2020
656b457
docs: Added first version of README.md file to the tests_integ directory
mgrandis Nov 27, 2020
77d5b91
chagne hard code FILE_TO_S3_URI_MAP, CODE_KEY_TO_FILE_MAP to be param…
mingkun2020 Nov 27, 2020
1871bc8
fix: Need to tell pytest in the MakeFile to only search for *.py file…
mgrandis Nov 27, 2020
6b3ab9f
chore: Minor README.md wording/format changes
mgrandis Nov 27, 2020
f1e0569
change file_to_s3_uri_map and code_key_to_file to be class variables
mingkun2020 Nov 27, 2020
58e14c7
fix: black and black-check Make commands now only check *.py files in…
mgrandis Nov 28, 2020
724dfdf
docs: Moved the test_integ readme file to the root, renamed it, refer…
mgrandis Dec 2, 2020
c1c274b
Merge branch 'develop' into foss-integ-test
mgrandis Dec 18, 2020
40a7827
refactor: Using LogicalIdGenerator.HASH_LENGTH in verify_stack_resour…
mgrandis Dec 19, 2020
cc19689
fix: Fix table_print tests syntax errors for python2
mgrandis Dec 23, 2020
2fc0bb1
refactor: Removed the table_print tests which are complicated to port…
mgrandis Dec 23, 2020
463e1e6
refactor: Revert newline removal at the end of appveyor.yml
mgrandis Dec 23, 2020
886c692
for testing appveyor only, will revert later
mingkun2020 Jan 7, 2021
e04853f
Revert "for testing appveyor only, will revert later"
mingkun2020 Jan 7, 2021
bccea06
test appveyor failure, will revert later
mingkun2020 Jan 7, 2021
26eed84
Revert "test appveyor failure, will revert later"
mingkun2020 Jan 7, 2021
8711cfa
just for testing appveyor failure, will revert later
mingkun2020 Jan 8, 2021
35b5b09
for testing only, will revert later, add ssh access to appveyor vm
mingkun2020 Jan 8, 2021
8237cbf
for testing only, will revert later
mingkun2020 Jan 8, 2021
9de384e
Revert "for testing only, will revert later"
mingkun2020 Jan 8, 2021
3aaa34c
revert all the previous test changes
mingkun2020 Jan 8, 2021
12bc745
create a appveyor config file for integration test
mingkun2020 Jan 11, 2021
8f33c82
move integration test to a separate appveyor yml file
mingkun2020 Jan 11, 2021
6806e78
delete extra blank line
mingkun2020 Jan 12, 2021
3d380b8
increase retry times to bypass Throttling
mingkun2020 Jan 12, 2021
d88bddd
black reformatting
mingkun2020 Jan 12, 2021
0bddb9a
refactor helper.py to have meaningful class name
mingkun2020 Jan 15, 2021
4848990
rename folder name and make command name to have the sam style with s…
mingkun2020 Jan 15, 2021
d070397
create a client provider class with lazy initialization
mingkun2020 Jan 15, 2021
b3930c1
add comments for clients
mingkun2020 Jan 15, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions DEVELOPMENT_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ will not work in Python3.6). If you want to test in many versions, you can creat
each version and flip between them (sourcing the activate script). Typically, we run all tests in
one python version locally and then have our ci (appveyor) run all supported versions.

### Integration tests

Integration tests are covered in detail in the [INTEGRATION_TESTS.md file](INTEGRATION_TESTS.md) of this repository.

Code Conventions
----------------

Expand Down
125 changes: 125 additions & 0 deletions INTEGRATION_TESTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# AWS SAM integration tests

These tests run SAM against AWS services by translating SAM templates, deploying them to Cloud Formation and verifying the resulting objects.

They must run successfully under Python 2 and 3.

## Run the tests

### Prerequisites

#### User and rights

An Internet connection and an active AWS account are required to run the tests as they will interact with AWS services (most notably Cloud Formation) to create and update objects (Stacks, APIs, ...).

AWS credentials must be configured either through a [credentials file](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html) or [environment variables](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html)

The user running the tests must have the following roles:

```
AmazonSQSFullAccess
AmazonSNSFullAccess
AmazonAPIGatewayAdministrator
AWSKeyManagementServiceFullAccess
AWSStepFunctionsFullAccess
```

If you plan on running the full tests suite, ensure that the user credentials you are running the tests with have a timeout of at least 30 minutes as the full suite can take more than 20 minutes to execute.

#### Initialize the development environment

If you haven't done so already, run the following command in a terminal at the root of the repository to initialize the development environment:

```
make init
```

### Running all the tests

From the root of the repository, run:

```
make integ-test
```

### Running a specific test file

From the command line, run:

```
pytest --no-cov path/to/the/test_file.py
```

For example, from the root of the project:

```sh
pytest --no-cov integration/single/test_basic_api.py
```

### Running a specific test

From the command line, run:

```
pytest --no-cov path/to/the/test_file.py::test_class::test_method
```

For example, from the root of the project:

```sh
pytest --no-cov integration/single/test_basic_api.py::TestBasicApi::test_basic_api
```

*We don't measure coverage for integration tests.*

## Write a test

1. Add your test templates to the `integration/resources/templates` single or combination folder.
2. Write an expected json file for all the expected resources and add it to the `integration/resources/expected`.
3. (Optional) Add the resource files (zip, json, etc.) to `integration/resources/code` and update the dictionaries in `integration/helpers/file_resources.py`.
4. Write and add your python test code to the `integration` single or combination folder.
5. Run it!

## Directory structure

### Helpers

Common classes and tools used by tests.

```
+-- helpers/
| +-- deployer Tools to deploy to Cloud Formation
| +-- base_test.py Common class from which all test classes inherit
| +-- file_resources.py Files to upload to S3
| +-- resource.py Helper functions to manipulate resources
| +-- template.py Helper functions to translate the template
```

`base_test.py` contains `setUpClass` and `tearDownClass` methods to respectively upload and clean the `file_resources.py` resources (upload the files to a new S3 bucket, empty and delete this bucket).

### Resources

File resources used by tests.

```
+-- resources
| +-- code Files to upload to S3
| +-- expected Files describing the expected created resources
| +-- templates Source SAM templates to translate and deploy
```

The matching *expected* and *template* files should have the same name.

For example, the `test_basic_api` test in the class `tests_integ/single/test_basic_api.py` takes `templates/single/basic_api.yaml` SAM template as input and verifies its result against `expected/single/basic_api.json`.

### Single

Basic tests which interact with only one service should be put here.

### Combination

Tests which interact with multiple services should be put there.

### Tmp

This directory is created on the first run and contains temporary and intermediary files used by the tests: sam templates with substituted variable values, translated temporary cloud formation templates, ...
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ init:
pip install -e '.[dev]'

test:
pytest --cov samtranslator --cov-report term-missing --cov-fail-under 95 tests
pytest --cov samtranslator --cov-report term-missing --cov-fail-under 95 tests/*

integ-test:
pytest --no-cov integration/*

black:
black setup.py samtranslator/* tests/* bin/*.py
black setup.py samtranslator/* tests/* integration/* bin/*.py

black-check:
black --check setup.py samtranslator/* tests/* bin/*.py
black --check setup.py samtranslator/* tests/* integration/* bin/*.py

# Command to run everytime you make changes to verify everything works
dev: test
Expand All @@ -30,6 +33,7 @@ Usage: $ make [TARGETS]
TARGETS
init Initialize and install the requirements and dev-requirements for this project.
test Run the Unit tests.
integ-test Run the Integration tests.
dev Run all development tests after a change.
pr Perform all checks before submitting a Pull Request.

Expand Down
24 changes: 24 additions & 0 deletions appveyor-integration-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: 1.0.{build}
image: Ubuntu

environment:
matrix:
- TOXENV: py27
PYTHON_VERSION: '2.7'
- TOXENV: py36
PYTHON_VERSION: '3.6'
- TOXENV: py37
PYTHON_VERSION: '3.7'
- TOXENV: py38
PYTHON_VERSION: '3.8'

build: off

install:
- sh: "source ${HOME}/venv${PYTHON_VERSION}/bin/activate"
- sh: "python --version"
- make init

test_script:
- make integ-test

Empty file added integration/__init__.py
Empty file.
Empty file.
Loading