diff --git a/Makefile b/Makefile index 45d7d59e2..ace8e28ed 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ clean: rm -rf .egg stacker.egg-info test-functional: - cd tests && bats . + cd tests && bats test_suite # General testing target for most development. test: lint test-unit test-unit3 diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 000000000..06b5fa413 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,8 @@ +permissions: + ./stacker.yaml.sh | stacker build - + +test: permissions + $(eval AWS_ACCESS_KEY_ID := $(shell ./stacker.yaml.sh | stacker info - 2>&1 | awk '/AccessKeyId/ {print $$3}')) + $(eval AWS_SECRET_ACCESS_KEY := $(shell ./stacker.yaml.sh | stacker info - 2>&1 | awk '/SecretAccessKey/ {print $$3}')) + $(eval STACKER_ROLE := $(shell ./stacker.yaml.sh | stacker info - 2>&1 | awk '/FunctionalTestRole/ {print $$3}')) + @STACKER_ROLE=$(STACKER_ROLE) AWS_ACCESS_KEY_ID=$(AWS_ACCESS_KEY_ID) AWS_SECRET_ACCESS_KEY=$(AWS_SECRET_ACCESS_KEY) ./run_test_suite.sh ${TESTS} diff --git a/tests/README.md b/tests/README.md index e41ab87f8..441ae03ba 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,4 +1,4 @@ -This directory contains the functional testing suite for stacker. It exercises all of stacker against a real AWS account. +This directory contains the functional testing suite for stacker. It exercises all of stacker against a real AWS account. Make sure you have the AWS credentials loaded into your environment when you run these steps. ## Setup @@ -7,27 +7,26 @@ This directory contains the functional testing suite for stacker. It exercises a ```console $ source venv/bin/activate ``` + 2. Set a stacker namespace & the AWS region for the test suite to use: ```console $ export STACKER_NAMESPACE=my-stacker-test-namespace + $ export AWS_DEFAULT_REGION=us-east-1 ``` -3. Generate an IAM user for the test suite to use: - ```console - $ ./stacker.yaml.sh | stacker build - - ``` -4. Grab the generated key pair for the user and set it in your shell: +3. Ensure that bats is installed: ```console - $ ./stacker.yaml.sh | stacker info - - $ export AWS_ACCESS_KEY_ID=access-key - $ export AWS_SECRET_ACCESS_KEY=secret-access-key - $ export STACKER_ROLE= + # On MacOS if brew is installed + $ brew install bats ``` -5. Run the test suite: + +4. Setup functional test environment & run tests: ```console - $ brew install bats - $ bats . + # To run all the tests + $ make -C tests test + # To run specific tests (ie: tests 1, 2 and 3) + $ TESTS="1 2 3" make -C tests test ``` diff --git a/tests/run_test_suite.sh b/tests/run_test_suite.sh new file mode 100755 index 000000000..22a97844d --- /dev/null +++ b/tests/run_test_suite.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +TEST_ARGS=$* + +if [ -z "$TEST_ARGS" ] +then + _TESTS="test_suite" +else + for T in ${TEST_ARGS} + do + _TESTS="${_TESTS} test_suite/$(printf %02d ${T})_*" + done +fi + +echo "bats ${_TESTS}" + +bats ${_TESTS} diff --git a/tests/suite.bats b/tests/suite.bats deleted file mode 100755 index 7e24cac05..000000000 --- a/tests/suite.bats +++ /dev/null @@ -1,1064 +0,0 @@ -#!/usr/bin/env bats - -load test_helper - -@test "stacker build - no config" { - stacker build - assert ! "$status" -eq 0 - assert_has_line -E "too few arguments|the following arguments are required: config" -} - -@test "stacker build - empty config" { - stacker build <(echo "") - assert ! "$status" -eq 0 - assert_has_line 'Should have more than one element' -} - -@test "stacker build - config with no stacks" { - stacker build - < "vpc";' - assert_has_line '"bastion2" -> "vpc";' - assert_has_line '"app1" -> "bastion1";' - assert_has_line '"app2" -> "bastion2";' - assert $(echo "$output" | grep -A 2 vpc | tail -n 2 | grep -c vpc) = '0' -} - -@test "stacker build - missing variable" { - needs_aws - - stacker build - < "vpc";' + assert_has_line '"bastion2" -> "vpc";' + assert_has_line '"app1" -> "bastion1";' + assert_has_line '"app2" -> "bastion2";' + assert $(echo "$output" | grep -A 2 vpc | tail -n 2 | grep -c vpc) = '0' +} diff --git a/tests/test_suite/09_stacker_build-missing_variable.bats b/tests/test_suite/09_stacker_build-missing_variable.bats new file mode 100644 index 000000000..e8f8a8cd1 --- /dev/null +++ b/tests/test_suite/09_stacker_build-missing_variable.bats @@ -0,0 +1,17 @@ +#!/usr/bin/env bats + +load ../test_helper + +@test "stacker build - missing variable" { + needs_aws + + stacker build - <