-
Notifications
You must be signed in to change notification settings - Fork 40
/
test.sh
executable file
·180 lines (155 loc) · 7.98 KB
/
test.sh
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
#!/bin/bash
START=`date +%s`
COOKIE_PATH="/tmp/act-test-cookie"
SUCCESS_COUNTER=0
TEST_COUNTER=0
SKIP_COUNTER=0
LAST_TEST_STATUS=0
declare -i SUCCESS_COUNTER
declare -i SKIP_COUNTER
declare -i TEST_COUNTER
FRIEND_CONTROLLER_HOST="http://controller.local:8090"
FRIEND_CONTROLLER_CREDENTIALS="admin@customer1:appdynamics123"
FRIEND_COOKIE_PATH="/tmp/act-test-friend-cookie"
ADMIN_CONTROLLER_HOST="http://controller.local:8090"
ADMIN_CONTROLLER_CREDENTIALS="root@system:appdynamics123"
ADMIN_COOKIE_PATH="/tmp/act-test-admin-cookie"
echo "Sourcing user config for controller host and credentials..."
source "$HOME/.appdynamics/act/config.sh"
echo "Will use the following controller for testing: $CONFIG_CONTROLLER_HOST"
function assert_equals {
TEST_COUNTER=$TEST_COUNTER+1
if [[ "$2" = "$1" ]]; then
SUCCESS_COUNTER=$SUCCESS_COUNTER+1
LAST_TEST_STATUS=0
echo -en "\033[0;32m.\033[0m"
else
LAST_TEST_STATUS=1
echo -e "\n\033[0;31mTest \033[0;34m$3\033[0;31m failed: \033[0;33m$1\033[0;31m doesn't equal \033[0;35m$2\033[0m"
fi
}
function assert_empty {
TEST_COUNTER=$TEST_COUNTER+1
if [[ -z "$1" ]]; then
SUCCESS_COUNTER=$SUCCESS_COUNTER+1
echo -en "\033[0;32m.\033[0m"
LAST_TEST_STATUS=0
else
LAST_TEST_STATUS=1
echo -e "\n\033[0;31mTest \033[0;34m$3\033[0;31m failed: \033[0;33m$1\033[0;31m is not an empty string."
fi
}
function assert_contains_substring {
TEST_COUNTER=$TEST_COUNTER+1
if [[ $2 = *$1* ]]; then
SUCCESS_COUNTER=$SUCCESS_COUNTER+1
echo -en "\033[0;32m.\033[0m"
LAST_TEST_STATUS=0
else
LAST_TEST_STATUS=1
echo -e "\n\033[0;31mTest \033[0;34m$3\033[0;31m failed: Couldn't find \033[0;33m$1\033[0;31m in \033[0;35m$2\033[0m"
fi
}
function assert_regex {
TEST_COUNTER=$TEST_COUNTER+1
if [[ $2 =~ $1 ]]; then
SUCCESS_COUNTER=$SUCCESS_COUNTER+1
echo -en "\033[0;32m.\033[0m"
LAST_TEST_STATUS=0
else
LAST_TEST_STATUS=1
echo -e "\n\033[0;31mTest \033[0;34m$3\033[0;31m failed: Couldn't find \033[0;33m$1\033[0;31m in \033[0;35m$2\033[0m"
fi
}
ACT="./act.sh -N -H $CONFIG_CONTROLLER_HOST -C $CONFIG_CONTROLLER_CREDENTIALS -J $COOKIE_PATH"
ACT_ADMIN="./act.sh -N -H $ADMIN_CONTROLLER_HOST -C $ADMIN_CONTROLLER_CREDENTIALS -J $ADMIN_COOKIE_PATH"
ACT_FRIEND="./act.sh -N -H $FRIEND_CONTROLLER_HOST -C $FRIEND_CONTROLLER_CREDENTIALS -J $FRIEND_COOKIE_PATH"
#### BEGIN TESTS ####
##### Test controller functionality #####
assert_contains_substring "Pong!" "`${ACT} controller ping`"
assert_contains_substring "Login Successful" "`${ACT} controller login`"
assert_contains_substring "<available>true</available>" "`${ACT} controller status`"
assert_regex "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+" "`${ACT} controller version`"
##### Create a test application
APPNAME="ACT_TEST_APPLICATION_${RANDOM}"
CREATE_APPLICATION="`${ACT} application create -t APM -n "$APPNAME"`"
assert_contains_substring "\"name\" : \"${APPNAME}\"," "$CREATE_APPLICATION"
if [[ $CREATE_APPLICATION =~ \"id\"\ \:\ ([0-9]+) ]] ; then
APPLICATION_ID=${BASH_REMATCH[1]}
##### List different entities #####
assert_contains_substring "<applications>" "`${ACT} application list`" "List Applications"
assert_contains_substring "<tiers>" "`${ACT} tier list -a $APPLICATION_ID`" "List Tiers"
assert_contains_substring "<business-transactions>" "`${ACT} bt list -a $APPLICATION_ID`" "List BTs"
assert_contains_substring "<nodes>" "`${ACT} node list -a $APPLICATION_ID`" "List Nodes"
assert_contains_substring "<policy-violations>" "`${ACT} healthrule violations -a $APPLICATION_ID -t BEFORE_NOW -d 1200`" "List health rule violations"
##### Export the given application #####
assert_contains_substring "<rule" "`${ACT} application export -a $APPLICATION_ID`" "Export Application"
##### Database Collector Create, List, Get, Delete #####
#DBMON_NAME="act_test_collector_$RANDOM"
#CREATE_DBMON="`${ACT} dbmon create -i ${DBMON_NAME} -h localhost -n db -u user -a "Default Database Agent" -t DB2 -p 1555 -s password`"
#assert_contains_substring "HTTP Status: 201" "${CREATE_DBMON}" "Create Database Collector"
#sleep 10
#assert_contains_substring "\"name\":\"${DBMON_NAME}\"," "`${ACT} dbmon list`" "List Database Collectors"
#echo $CREATE_DBMON
#if [[ $CREATE_DBMON =~ \"id\"\:([0-9]+) ]] ; then
# COLLECTOR_ID=${BASH_REMATCH[1]}
# assert_contains_substring "\"name\" : \"${DBMON_NAME}\"," "`${ACT} dbmon get -c $COLLECTOR_ID`"
# assert_contains_substring '"status" : "SUCCESS",' "`${ACT} dbmon delete -c $COLLECTOR_ID`"
#else
# SKIP_COUNTER=$SKIP_COUNTER+2
# echo -en "\033[0;33m!!\033[0m"
#fi
##### Events #####
assert_contains_substring "Successfully created the event id:" "`${ACT} event create -a ${APPLICATION_ID} -s "Test" -l INFO -e CUSTOM`" "Create custom event"
assert_contains_substring "Successfully created the event id:" "`${ACT} event create -a ${APPLICATION_ID} -s "Test" -l INFO -e APPLICATION_DEPLOYMENT`" "Create application deployment"
assert_contains_substring "Successfully created the event id:" "`${ACT} event create -a ${APPLICATION_ID} -s "Urlencoding Test" -c "With Comment" -l INFO -e APPLICATION_DEPLOYMENT`" "Create application deployment"
# It takes the controller several seconds to update the list of events, so we (currently) skip checking the existence of the ids above
assert_contains_substring "<events>" "`${ACT} event list -a ${APPLICATION_ID} -t BEFORE_NOW -d 60 -e APPLICATION_DEPLOYMENT -s INFO`"
##### Action Templates #####
assert_contains_substring '"success":true' "`${ACT} actiontemplate import -t httprequest tests/httptemplate.json`" "Import action template"
LIST_ACTION_TEMPLATES=`${ACT} actiontemplate list -t httprequest`
assert_contains_substring '"name" : "MyCustomHTTPTemplate",' "${LIST_ACTION_TEMPLATES}" "List action templates"
if [[ $LIST_ACTION_TEMPLATES =~ \"id\"\ :\ ([0-9]+) ]] ; then
TEMPLATE_ID=${BASH_REMATCH[1]}
assert_contains_substring "HTTP Status: 204" "`${ACT} actiontemplate delete -i ${TEMPLATE_ID}`" "Delete action template"
else
SKIP_COUNTER+=1
echo -en "\033[0;33m!\033[0m"
fi
##### Federation #####
FRIEND_LOGIN="`${ACT_FRIEND} controller login`"
assert_contains_substring "Login Successful" "$FRIEND_LOGIN" "Federation Friend login successful"
if [ $LAST_TEST_STATUS -eq 0 ]; then
assert_contains_substring "Federation Key for account {customer1}" "`${ACT} federation createkey -n key_${RANDOM}`" "Create federation key"
assert_contains_substring "HTTP Status: 200" "`${ACT_FRIEND} federation setup -h "${CONFIG_CONTROLLER_HOST}" -c "${CONFIG_CONTROLLER_CREDENTIALS}"`" "Federation Setup"
else
SKIP_COUNTER=$SKIP_COUNTER+2
echo -en "\033[0;33m!!\033[0m"
fi
##### Configurations #####
assert_contains_substring "sim.docker.container.node.maxCacheSize" "`${ACT_ADMIN} configuration list`" "Configuration List"
assert_contains_substring "sim.docker.container.node.maxCacheSize" "`${ACT_ADMIN} configuration get -n sim.docker.container.node.maxCacheSize`" "Configuration List"
CONFIG_VALUE=${RANDOM}
assert_contains_substring "${CONFIG_VALUE}" "`${ACT_ADMIN} configuration set -n sim.docker.container.node.maxCacheSize -v ${CONFIG_VALUE}`" "Configuration List"
##### Error handling #####
assert_equals "Error" "`env CONFIG_HTTP_TIMEOUT=1 ./act.sh -H 127.0.0.2:8009 controller ping`"
assert_equals "ERROR: Missing application: Please provide an argument for parameter -a" "`${ACT} event create`" "Missing required argument"
##### Delete the test application
assert_contains_substring "HTTP Status: 204" "`${ACT} application delete $APPLICATION_ID`"
fi
#### END TESTS ####
declare -i PERCENTAGE
PERCENTAGE=$((($SUCCESS_COUNTER*100)/($TEST_COUNTER)))
if [ $PERCENTAGE -eq 100 ]; then
echo -e "\033[0;32m"
elif [ $PERCENTAGE -ge 80 ]; then
echo -e "\033[0;33m"
else
echo -e "\033[0;31m"
fi
rm $COOKIE_PATH $FRIEND_COOKIE_PATH $ADMIN_COOKIE_PATH
END=`date +%s`
echo -e "\n$SUCCESS_COUNTER/$TEST_COUNTER ($PERCENTAGE%) tests completed in $((END-START))s.\033[0m"
if [ $SKIP_COUNTER -gt 0 ] ; then
echo -e "\033[0;33m$SKIP_COUNTER tests have been skipped.\033[0m"
fi