generated from honeycombio/.github
-
Notifications
You must be signed in to change notification settings - Fork 6
/
test.bats
105 lines (90 loc) · 2.54 KB
/
test.bats
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# This script checks that what's deployed in AWS is "correct" according to our
# expectations. It does not, itself, run `terraform apply` or `terraform
# destroy`.
### BEFORE:
# Configure terraform and run `terraform apply`.
###
### Run:
# bats test.bats # Bats can be installed using homebrew (OS X) or apt (Ubuntu)
#
# Exit status 254 on all your tests most likely means it can't find the
# resources - probably you haven't run `terraform apply` or you're using the
# wrong credentials/profile.
###
### AFTER:
# Clean up by running `terraform destroy`.
###
# If we've set an aws profile in base.tf, run our tests with that profile.
#
# (`sed` normalizes whitespace; the lookbehind in our grep can't use
# /profile *= # / because lookbehinds must be a known width)
aws_profile_from_base_tf=$(cat $BATS_TEST_DIRNAME/base.tf | sed 's/ */ /g' | grep -P -o '(?<=profile = ").*(?=")' | head -n 1)
if [[ "$aws_profile_from_base_tf" ]]; then
AWS_PROFILE="$aws_profile_from_base_tf"
fi
@test "default module creation works" {
run aws cloudwatch get-metric-stream --name cms_default
[ "$status" -eq 0 ]
}
@test "module sets tags on 'aws_cloudwatch_metric_stream'" {
run aws cloudwatch get-metric-stream --name cms_with_tags --output text --query "Arn"
arn=$output
run aws cloudwatch list-tags-for-resource --resource-arn $arn
local expected=$(cat <<EOF
{
"Tags": [
{
"Key": "Environment",
"Value": "ismith-sandbox"
}
]
}
EOF
)
[ "$status" -eq 0 ]
if ! [ "$output" == "$expected" ]; then
echo "Tags for cms_default:"
echo "Expected:"
echo "$expected"
echo "Actual:"
echo "$output"
return 1
fi
}
expected_filters=$(cat <<EOF
[
{
"Namespace": "AWS/RDS"
},
{
"Namespace": "AWS/ELB"
}
]
EOF
)
@test "module sets include_filters 'aws_cloudwatch_metric_stream'" {
run aws cloudwatch get-metric-stream --name cms_with_includes --query "IncludeFilters"
local expected=$expected_filters
[ "$status" -eq 0 ]
if ! [ "$output" == "$expected" ]; then
echo "Tags for cms_default:"
echo "Expected:"
echo "$expected"
echo "Actual:"
echo "$output"
return 1
fi
}
@test "module sets exclude_filters 'aws_cloudwatch_metric_stream'" {
run aws cloudwatch get-metric-stream --name cms_with_excludes --query "ExcludeFilters"
local expected=$expected_filters
[ "$status" -eq 0 ]
if ! [ "$output" == "$expected" ]; then
echo "Tags for cms_default:"
echo "Expected:"
echo "$expected"
echo "Actual:"
echo "$output"
return 1
fi
}