forked from cloudfoundry/cf-deployment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest
executable file
·219 lines (175 loc) · 5.81 KB
/
test
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#!/bin/bash
set -ue
exit_code=0
GREEN='\033[0;32m'
LIGHT_GREEN='\033[0;92m'
RED='\033[0;31m'
LIGHT_RED='\033[1;31m'
YELLOW='\033[0;93m'
NOCOLOR='\033[0m'
: "${RUN_SEMANTIC:="false"}"
script_home="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
home="$( cd "${script_home}/.." && pwd )"
# suite_name should be defined by each of our test suite functions
suite_name="UNDEFINED"
# Grab each of our test suites, exercised by test_opsfile_interpolation()
for script in `ls ${script_home}/*.sh`; do
source $script
done
# If we get killed, kill backgrounded processes
trap 'kill $(jobs -p) > /dev/null 2>&1' SIGTERM SIGINT
fail() {
echo -e "${RED} FAIL - ${LIGHT_RED} $suite_name ${RED} - ${NOCOLOR} $1"
exit_code=1
}
pass() {
echo -e "${GREEN} PASS - ${YELLOW} $suite_name ${GREEN} - ${NOCOLOR} $1"
}
interpolate() {
local vars_store=$(mktemp)
cp ${home}/scripts/fixtures/unit-test-vars-store.yml $vars_store
bosh interpolate --vars-store $vars_store --var-errs -v system_domain=foo.bar.com ${home}/cf-deployment.yml $@ > /dev/null
local exit_code=$?
rm $vars_store
return $exit_code
}
check_interpolation() {
if [[ ${1} == name:* ]]; then
name_under_test=$1
empty_string=""
ops_under_test="${name_under_test/name: /$empty_string}"; shift
else
ops_under_test="${1}"
fi
if interpolate "-o $@"; then
pass "${ops_under_test}"
else
fail "${ops_under_test}"
fi
}
test_opsfile_interpolation() {
test_standard_ops &
test_experimental_ops &
test_test_ops &
test_legacy_ops &
test_addons_ops &
test_backup_and_restore_ops &
for job in $(jobs -p); do
wait $job || exit_code=1
done
}
test_iaas_opsfile_interpolation() {
test_iaas_ops &
for job in $(jobs -p); do
wait $job || exit_code=1
done
}
test_example_vars_files_interpolation() {
test_example_vars_files &
for job in $(jobs -p); do
wait $job || exit_code=1
done
}
ensure_test_opsfiles_not_in_readme() {
pushd ${home} > /dev/null
local opsfiles=$(ls operations/test/*.yml)
local output=$(grep $(for x in $opsfiles; do echo -n " -e $x"; done;) README.md -c)
if [ $output == "0" ]; then
pass "Test opsfiles do not appear in README"
else
fail "Test opsfiles appear in README"
fi
popd > /dev/null
}
ensure_opsfiles_in_readme() {
local readme=$1
shift
suite_name="$readme"
pushd ${home} > /dev/null
for x in $@; do
local basename=$(basename $x)
if [ $(grep \($basename\) $readme -c) != "0" ]; then
pass "$x is in $readme"
else
fail "$x does not appear in $readme"
fi
done;
popd > /dev/null
}
ensure_opsfiles_in_readme_exist() {
local ops_dir=$1
local readme=${ops_dir}/README.md
ops_files_in_readme=$(cat ${readme} | grep -Eo '\((.+\.yml)\)' | cut -d '(' -f2 | cut -d ')' -f1)
pushd ${home} > /dev/null
for ops_file in ${ops_files_in_readme}; do
set +e
ls ${ops_dir}/${ops_file} > /dev/null 2>&1
local ops_file_exists=$?
set -e
suite_name="${ops_dir}/${ops_file}"
if [ "${ops_file_exists}" == "0" ]; then
pass "$ops_file from $readme exists"
else
fail "$ops_file from $readme doesn't exist"
fi
done
popd > /dev/null
}
ensure_opsfiles_in_tests() {
local test=$1
shift
suite_name="$test"
pushd ${home} > /dev/null
for x in $@; do
local basename=$(basename $x)
if [ $(grep "[^/]$basename" $test -c) != "0" ]; then
pass "$x is tested in $test"
else
fail "$x is ${RED}NOT${NOCOLOR} tested in $test"
fi
done;
popd > /dev/null
}
main() {
echo
echo -e "${LIGHT_GREEN} ***** Begin affirmative readme operations tests ***** ${NOCOLOR}"
ensure_opsfiles_in_readme "operations/README.md" $(ls operations/*.yml)
ensure_opsfiles_in_readme "operations/legacy/README.md" $(ls operations/legacy/*.yml)
ensure_opsfiles_in_readme "operations/community/README.md" $(ls operations/community/*.yml)
ensure_opsfiles_in_readme "operations/experimental/README.md" $(ls operations/experimental/*.yml)
ensure_opsfiles_in_readme "operations/backup-and-restore/README.md" $(ls operations/backup-and-restore/*.yml)
echo
echo -e "${LIGHT_GREEN} ***** Begin affirmative operations in readme tests ***** ${NOCOLOR}"
ensure_opsfiles_in_readme_exist "operations"
ensure_opsfiles_in_readme_exist "operations/legacy"
ensure_opsfiles_in_readme_exist "operations/community"
ensure_opsfiles_in_readme_exist "operations/experimental"
ensure_opsfiles_in_readme_exist "operations/backup-and-restore"
echo
echo -e "${LIGHT_GREEN} ***** Begin negative readme operations tests ***** ${NOCOLOR}"
ensure_test_opsfiles_not_in_readme
echo
echo -e "${LIGHT_GREEN} ***** Begin test coverage analysis ***** ${NOCOLOR}"
ensure_opsfiles_in_tests "scripts/test-standard-ops.sh" $(ls operations/*.yml)
ensure_opsfiles_in_tests "scripts/test-legacy-ops.sh" $(ls operations/legacy/*.yml)
ensure_opsfiles_in_tests "scripts/test-test-ops.sh" $(ls operations/test/*.yml)
ensure_opsfiles_in_tests "scripts/test-experimental-ops.sh" $(ls operations/experimental/*.yml)
ensure_opsfiles_in_tests "scripts/test-addons-ops.sh" $(ls operations/addons/*.yml)
ensure_opsfiles_in_tests "scripts/test-backup-and-restore-ops.sh" $(ls operations/backup-and-restore/*.yml)
echo
echo -e "${LIGHT_GREEN} ***** Begin interpolation operations tests ***** ${NOCOLOR}"
test_opsfile_interpolation
echo
echo -e "${LIGHT_GREEN} ***** Begin interpolation iaas operations tests ***** ${NOCOLOR}"
test_iaas_opsfile_interpolation
# echo
# echo -e "${LIGHT_GREEN} ***** Begin interpolation example vars files tests ***** ${NOCOLOR}"
# test_example_vars_files_interpolation
if [ "$RUN_SEMANTIC" == "true" ]; then
echo
echo -e "${LIGHT_GREEN} ***** Begin semantic operations tests ***** ${NOCOLOR}"
semantic_tests
fi
exit $exit_code
}
main