Skip to content
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

support for running all the test cases #14

Merged
merged 94 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from 90 commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
d2aa925
added python plugin
macnev2013 Jan 4, 2023
72729c2
Updated config.yml
macnev2013 Jan 4, 2023
2505ba1
updated deps
macnev2013 Jan 4, 2023
50734c4
removed lib versions
macnev2013 Jan 4, 2023
c0aa68a
added missing file
macnev2013 Jan 4, 2023
d4fe6d5
updated python version
macnev2013 Jan 4, 2023
b5c7e8a
updated python version
macnev2013 Jan 4, 2023
4f96808
changed ordering
macnev2013 Jan 4, 2023
86ba55d
added golang/python org
macnev2013 Jan 4, 2023
00250ef
added versioninign
macnev2013 Jan 4, 2023
5701d0e
updated golang version
macnev2013 Jan 4, 2023
3d0254c
golang version update
macnev2013 Jan 4, 2023
0ed141b
go versionchanged to string
macnev2013 Jan 4, 2023
b576bd1
reloaded go images
macnev2013 Jan 4, 2023
0090d97
resource class added
macnev2013 Jan 4, 2023
4fe8049
resource class added
macnev2013 Jan 4, 2023
7fb9c71
updated build
macnev2013 Jan 5, 2023
ddbfbe8
changed bin building
macnev2013 Jan 5, 2023
3c81b98
updated testing mechanism
macnev2013 Jan 5, 2023
68cbd9d
updated value
macnev2013 Jan 5, 2023
0257868
updated testing mechanism
macnev2013 Jan 5, 2023
637d0c4
updated timeout
macnev2013 Jan 5, 2023
f6cfa35
using go commands
macnev2013 Jan 5, 2023
8541d1d
updated env for buff output
macnev2013 Jan 5, 2023
651cdb4
removed cd
macnev2013 Jan 5, 2023
05f8dc8
updated test command
macnev2013 Jan 5, 2023
7a34cde
using raw golang
macnev2013 Jan 5, 2023
4d588f8
using raw golang
macnev2013 Jan 5, 2023
c32f981
updated testing mechansim
macnev2013 Jan 6, 2023
ef91855
updated resource class to large
macnev2013 Jan 6, 2023
596807f
testing workflow behaviour
macnev2013 Jan 6, 2023
a82cc5f
invoking wf
macnev2013 Jan 6, 2023
1e3be8a
updated wf
macnev2013 Jan 6, 2023
1e1491c
wf dependancies
macnev2013 Jan 6, 2023
0848af0
workspace attach test
macnev2013 Jan 6, 2023
3a467b5
removed working dir
macnev2013 Jan 6, 2023
43857aa
removed dir creation
macnev2013 Jan 6, 2023
c7d2ea4
added build persistence
macnev2013 Jan 6, 2023
d06082e
added persistence
macnev2013 Jan 6, 2023
4372cd4
debugging prints
macnev2013 Jan 6, 2023
bed75d9
restarting pipeline
macnev2013 Jan 6, 2023
210ab1a
updated config
macnev2013 Jan 6, 2023
2a5e505
added list in terraform folder
macnev2013 Jan 6, 2023
388f131
added exception
macnev2013 Jan 6, 2023
e51efaf
commented workflow
macnev2013 Jan 6, 2023
9a861e8
updated tf path
macnev2013 Jan 6, 2023
41a5ddb
added print
macnev2013 Jan 6, 2023
f7b1dea
added more logs
macnev2013 Jan 6, 2023
9288e19
updated circleci config
macnev2013 Jan 6, 2023
ecc5438
updated wf
macnev2013 Jan 6, 2023
5631578
python build command
macnev2013 Jan 9, 2023
0c13fbf
fixed syntax
macnev2013 Jan 9, 2023
8a4d194
adding python command
macnev2013 Jan 9, 2023
38f291e
updated filename
macnev2013 Jan 9, 2023
7591bec
removed unused args
macnev2013 Jan 9, 2023
cfb7b7f
added support for bin generation
macnev2013 Jan 9, 2023
8976c3b
added ls for debugging
macnev2013 Jan 9, 2023
59f2e49
removed tempfile usage
macnev2013 Jan 9, 2023
aca4841
removed tempfile usage
macnev2013 Jan 9, 2023
16d28d5
added new stage
macnev2013 Jan 9, 2023
0bc2358
added support for std output
macnev2013 Jan 9, 2023
4a923ac
updated tests to support parrallel executions
macnev2013 Jan 10, 2023
795c0e8
updated requiremnents
macnev2013 Jan 10, 2023
32f7e79
moved to github actions
macnev2013 Jan 10, 2023
a15c934
added services
macnev2013 Jan 10, 2023
9edc23d
added from json
macnev2013 Jan 10, 2023
d32ace7
added serice
macnev2013 Jan 10, 2023
4e9ed68
updated action
macnev2013 Jan 10, 2023
bf8274a
minor fix
macnev2013 Jan 10, 2023
42feab8
minor fix
macnev2013 Jan 10, 2023
025536b
added support for service
macnev2013 Jan 10, 2023
c4e5d66
added testing for specific service
macnev2013 Jan 10, 2023
43de7ae
running tests for all services
macnev2013 Jan 10, 2023
43c3091
test runs for specific service
macnev2013 Jan 11, 2023
da90aa6
fix: workflow to run without dispatch
macnev2013 Jan 11, 2023
3602799
fix: workflow or syntax
macnev2013 Jan 11, 2023
1275906
upgrade actions/setup-python@v4
alexrashed Jan 11, 2023
207acd8
add JUnit test result publishing
alexrashed Jan 11, 2023
4bfeccc
upgrade EnricoMi/publish-unit-test-result-action
alexrashed Jan 11, 2023
c7117fe
fix configuration of publish-unit-test-result-action
alexrashed Jan 11, 2023
488a2b2
fix: report generation patched
macnev2013 Jan 12, 2023
937ada5
update: added localstack implemented services, reformatted utils, upd…
macnev2013 Jan 12, 2023
27368e3
added single service
macnev2013 Jan 12, 2023
fef13bd
removed annotation
macnev2013 Jan 12, 2023
bd44e0f
added: support to run ls supported services
macnev2013 Jan 12, 2023
4a8ed4f
updated: workflow max-parallel, run for all service
macnev2013 Jan 12, 2023
416195c
Pytest plugin fork (#13)
macnev2013 Jan 13, 2023
63bcf72
removed: circleci workflow
macnev2013 Jan 13, 2023
8763b03
removed: unused code
macnev2013 Jan 13, 2023
67a5067
added formatting, makefile, updated project structure (#15)
macnev2013 Jan 17, 2023
b2c1d6f
running parallel tests for ec2 (#16)
macnev2013 Jan 20, 2023
2d4e3b8
review resolution (#17)
macnev2013 Jan 23, 2023
ce7a583
removed docker-compose (#18)
macnev2013 Jan 23, 2023
26537fb
readme updated (#19)
macnev2013 Jan 23, 2023
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
88 changes: 0 additions & 88 deletions .circleci/config.yml

This file was deleted.

88 changes: 88 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
on:
schedule:
- cron: '0 19 * * 6'
workflow_dispatch:
inputs:
services:
default: 'ls-community'
type: string
description: name of the service to execute tests for (e.g. "ls-community", "ls-pro", "ls-all", "s3,iam,ec2")
localstack-image:
required: false
type: string
default: 'localstack/localstack:latest'
description: localstack docker image name to test against
# disabled pipeline for push events, as we want to run the pipeline only on a schedule or manually
# push:
# branches:
# - pytest-plugin
macnev2013 marked this conversation as resolved.
Show resolved Hide resolved

name: Terraform Tests
jobs:

prepare_list:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: 'true'
- id: set-matrix
run: echo "matrix=$(python -m terraform_pytest.get-services ${{ github.event.inputs.services || 'ls-community' }})" >> $GITHUB_OUTPUT
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}

test_service:
needs: prepare_list
strategy:
max-parallel: 10
fail-fast: false
matrix:
service: ${{ fromJson(needs.prepare_list.outputs.matrix) }}
runs-on: ubuntu-latest

steps:

- uses: actions/checkout@v3
with:
submodules: 'true'

- uses: actions/setup-go@v3
with:
go-version: '1.18.x'
cache: true
cache-dependency-path: terraform-provider-aws/go.sum

- name: Set up Python 3.10.5
uses: actions/setup-python@v4
with:
python-version: '3.10.5'
cache: 'pip'

- name: Install system dependencies
run: |
sudo apt update --fix-missing
sudo apt install libsasl2-dev -y
pip install --upgrade pip
pip install -r requirements.txt

- name: Patch Terraform Provider
run: |
cd terraform-provider-aws && go mod vendor
cd ../
python -m terraform_pytest.main patch

- name: Build ${{ matrix.service }} Binary
run: |
python -m terraform_pytest.main build -s ${{ matrix.service }}
ls -la terraform-provider-aws/test-bin

- name: Run ${{ matrix.service }} Tests
run: |
python -m pytest --junitxml=target/reports/pytest.xml terraform-provider-aws/internal/service/${{ matrix.service }} -s -v --ls-start --ls-image ${{ github.event.inputs.localstack-image || 'localstack/localstack:latest' }}

- name: Publish ${{ matrix.service }} Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
junit_files: target/reports/*.xml
check_name: ${{ matrix.service }} Terraform Test Results
16 changes: 7 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
*~
*.swp
*.log
*.bak

.vscode
.DS_Store
.idea
*.iml

build/
.venv
.pytest_cache
__pycache__
target
**/*.test
report.xml
6 changes: 0 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
[submodule "localstack"]
path = localstack
url = https://github.com/localstack/localstack.git
[submodule "terraform-provider-aws"]
path = terraform-provider-aws
url = https://github.com/hashicorp/terraform-provider-aws.git
alexrashed marked this conversation as resolved.
Show resolved Hide resolved
[submodule "moto"]
path = moto
url = git@github.com:localstack/moto
26 changes: 26 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

VENV_BIN ?= python3 -m venv
VENV_DIR ?= .venv
PIP_CMD ?= pip3

ifeq ($(OS), Windows_NT)
VENV_ACTIVATE = $(VENV_DIR)/Scripts/activate
else
VENV_ACTIVATE = $(VENV_DIR)/bin/activate
endif

$(VENV_ACTIVATE):
test -d $(VENV_DIR) || $(VENV_BIN) $(VENV_DIR)
$(VENV_RUN); $(PIP_CMD) install --upgrade pip setuptools wheel plux
touch $(VENV_ACTIVATE)

VENV_RUN = . $(VENV_ACTIVATE)

venv: $(VENV_ACTIVATE) ## Create a new (empty) virtual environment

install:
$(VENV_RUN); $(PIP_CMD) install -r requirements.txt

format:
macnev2013 marked this conversation as resolved.
Show resolved Hide resolved
$(VENV_RUN); python -m isort .; python -m black .
96 changes: 35 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,61 +1,35 @@
Terraform vs LocalStack
=======================

This repository contains scripts and CI configurations to to run the Terraform Acceptance test suite of the AWS provider against LocalStack

## Utilities

Some utilities for local development:

* `bin/list-tests [--all]`: list the available tests by parsing the go test files.
* `bin/install-aws-test` creates the binary for running the test suite (and installs it into `$HOME/.cache/localstack/aws.test`. requires go 1.16
* `bin/run-tests [test]` run a specific test. this installs and runs localstack in a background process. add the flag `-t` to test against an already running localstack instance.

## Finding and running tests

After running `bin/install-aws-test`, use `bin/run-tests [OPTIONS...] [TESTS...]` to run individual tests or entire test suites.

Here are some examples:

* `bin/run-tests TestAccAWSAPIGatewayResource`
* `bin/run-tests -t TestAccAWSAPIGatewayResource`: same as above, but does not start localstack
* `bin/run-tests TestAccAWSAPIGateway`: runs all tests that match `TestAccAWSAPIGateway` (run `bin/list-tests TestAccAWSAPIGateway` to see which ones will be executed)
* `bin/run-tests -e TestAccAWSAPIGatewayV2 TestAccAWSAPIGateway`: same as above, but excludes all tests that match `TestAccAWSAPIGatewayV2`.
* `bin/run-tests -i localstack-tests.incl.txt`: runs all tests listed in the text file

You can use `bin/list-tests` with the same parameters to see which tests will be executed,
or to find specific tests based on patterns.

For example:

```
% bin/list-tests Queue
TestAccAWSBatchJobQueue
TestAccAWSGameliftGameSessionQueue
TestAccAWSMediaConvertQueue
TestAccAWSSQSQueue
TestAccAWSSQSQueuePolicy
TestAccDataSourceAwsBatchJobQueue
TestAccDataSourceAwsSqsQueue
```

or

```
% bin/list-tests "Data.*Queue"
TestAccDataSourceAwsBatchJobQueue
TestAccDataSourceAwsSqsQueue
```

## Generating the test reports

Test logs are aggregated into `build/tests/*.log`, the command `bin/create-report` will create junit-like xml reports.
These can then be rendered into html using `bin/create-report-html`, which also creates a summary page in `build/report.html`.
For rendering html, you need `junit2html`.

## Travis config

### Build cache

The Travis-CI worker caches the built `aws.test` binary across builds.
The first build may therefore take a while.
# Localstack Terraform Test Runner

This is a test runner for localstack and terraform. It will run a test cases from the hashicrop [terraform provider aws](https://github.com/hashicorp/terraform-provider-aws.git) against Localstack Instance.

Purpose of this project is to externalize the test cases from the localstack repo and run them against localstack to gather parity metrics.

## Installation
1. Clone the repository with submodules`
2. Run `make venv` to create a virtual environment
3. Run `make install` to install the dependencies

## How to run?
1. Run `python -m terraform_pytest.main patch` to apply the patch to the terraform provider aws
alexrashed marked this conversation as resolved.
Show resolved Hide resolved
2. Run `python -m terraform_pytest.main build -s s3` to build testing binary for the golang module
3Now you are ready to use `python -m pytest` commands to list and run test cases from golang

## How to run test cases?
- To list down all the test case from a specific service, run `python -m pytest terraform-provider-aws/internal/service/<service> --collect-only -q`
- To run a specific test case, run `python -m pytest terraform-provider-aws/internal/service/<service>/<test-file> -k <test-case-name> --ls-start` or `python -m pytest terraform-provider-aws/internal/service/<service>/<test-file>::<test-case-name> --ls-start`
- Additional environment variables can be added by appending it in the start of the command, i.e. `AWS_ALTERNATE_REGION='us-west-2' python -m pytest terraform-provider-aws/internal/service/<service>/<test-file>::<test-case-name> --ls-start`

## Default environment variables
- **TF_ACC**: `1`
- **AWS_ACCESS_KEY_ID**: `test`
- **AWS_SECRET_ACCESS_KEY**: `test`
- **AWS_DEFAULT_REGION**: `us-west-1`
- **AWS_ALTERNATE_ACCESS_KEY_ID**: `test`
- **AWS_ALTERNATE_SECRET_ACCESS_KEY**: `test`
- **AWS_ALTERNATE_SECRET_ACCESS_KEY**: `test`
- **AWS_ALTERNATE_REGION**: `us-east-2`
- **AWS_THIRD_REGION**: `eu-west-1`

## Options
- `--ls-start`: Start localstack instance before running the test cases
- `--ls-image`: Specify the localstack image to use, default is `localstack/localstack:latest`
Loading