forked from cloudtools/stacker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_helper.bash
58 lines (48 loc) · 1.45 KB
/
test_helper.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env bash
# To make the tests run faster, we don't wait between calls to DescribeStacks
# to check on the status of Create/Update.
export STACKER_STACK_POLL_TIME=0
if [ -z "$STACKER_NAMESPACE" ]; then
>&2 echo "To run these tests, you must set a STACKER_NAMESPACE environment variable"
exit 1
fi
if [ -z "$STACKER_ROLE" ]; then
>&2 echo "To run these tests, you must set a STACKER_ROLE environment variable"
exit 1
fi
# Setup a base .aws/config that can be use to test stack configurations that
# require stacker to assume a role.
export AWS_CONFIG_DIR=$(mktemp -d)
export AWS_CONFIG_FILE="$AWS_CONFIG_DIR/config"
cat <<EOF > "$AWS_CONFIG_FILE"
[default]
region = us-east-1
[profile stacker]
region = us-east-1
role_arn = ${STACKER_ROLE}
credential_source = Environment
EOF
# Simple wrapper around the builtin bash `test` command.
assert() {
builtin test "$@"
}
# Checks that the given line is in $output.
assert_has_line() {
echo "$output" | grep "$@" 1>/dev/null
}
# This helper wraps "stacker" with bats' "run" and also outputs debug
# information. If you need to execute the stacker binary _without_ calling
# "run", you can use "command stacker".
stacker() {
echo "$ stacker $@"
run command stacker "$@"
echo "$output"
echo
}
# A helper to tag a test as requiring access to AWS. If no credentials are set,
# then the tests will be skipped.
needs_aws() {
if [ -z "$AWS_ACCESS_KEY_ID" ]; then
skip "aws credentials not set"
fi
}