Skip to content

Commit

Permalink
Add simple test harness
Browse files Browse the repository at this point in the history
  • Loading branch information
Jberlinsky committed Jan 29, 2019
1 parent f81da4c commit 782747f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
credentials.test.json
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.PHONY: test
test:
./test/test.sh
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,12 @@ To run the example module tests after creating a new repository:
- Create a Service Account key in `/credentials.json` (relative to the new repository location)
- `cp test/fixtures/shared/terraform.tfvars.sample test/fixtures/shared/terraform.tfvars` and edit `test/fixtures/shared/terraform.tfvars`
- Run `make test_integration_docker`.

## Automated Testing

When making changes to this template, the tests on the example module should be run to sanity-check changes, with the goal of ensuring that this template is functional at all times. These steps have been automated, and can be run as follows:

1. Download a service account key for the project in which you want to run the generated module's tests as `/credentials.test.json`
2. Run `make test`

If the automated test fails, it will clean up resources that the module created, and leave `../terraform-google-module-test` in place for review. Otherwise, all resources will be cleaned up, and the generated module will be deleted.
25 changes: 25 additions & 0 deletions test/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

##############################################################
# Simple Test Harness #
# Instantiates the cookiecutter template, and runs its tests #
##############################################################

_curdir=$(pwd)
cd ..
cookiecutter --no-input "${_curdir}" module_name=module-test
cd ./terraform-google-module-test || exit 1
cp "${_curdir}/credentials.test.json" ./credentials.json
_project_id=$(cat credentials.json | jq -r '.project_id')
tee ./test/fixtures/shared/terraform.tfvars <<EOF
project_id="${_project_id}"
EOF
make test_integration_docker
_result=$?
if [ "$_result" -ne "0" ]; then
make docker_destroy
exit $_result
fi
cd .. || exit 1
rm -rf terraform-google-module-test
cd "${_curdir}" || exit 1

0 comments on commit 782747f

Please sign in to comment.