a94076f584b0d7e426858fa245b7ef53b08eb762
[integration.git] / test / mocks / datafilecollector-testharness / auto-test / README.md
1 ## Running automated test case and test suites
2 Test cases run a single test case and test suites run one or more test cases in a sequence.
3
4 ##Overall structure and setup
5 Test cases and test suites are written as bash scripts which call predefined functions in two other bash scripts
6 located in ../common dir.
7 The functions are described further below.
8 The integration repo is needed as well as docker.
9 If needed setup the ``DFC_LOCAL_IMAGE`` and ``DFC_REMOTE_IMAGE`` env var in test_env.sh to point to the dfc images (local registry image or next registry image) without the image tag.
10 The predefined images should be ok for current usage:
11
12 ``DFC_REMOTE_IMAGE=nexus3.onap.org:10001/onap/org.onap.dcaegen2.collectors.datafile.datafile-app-server``
13
14 ``DFC_LOCAL_IMAGE=onap/org.onap.dcaegen2.collectors.datafile.datafile-app-server``
15
16 If the test cases/suites in this dir are not executed in the auto-test dir in the integration repo, then the ``SIM_GROUP`` env var need to point to the ``simulator-group`` dir. 
17 See instructions in the test_env.sh. The ../common dir is needed as well in the case. That is, it is possible to have auto-test dir (and the common dir) somewhere else
18 than in the integration repo but the simulator-group and common dir need to be available.
19
20 ##Test cases and test suites naming.
21 Each file filename should have the format ``<tc-id>.sh`` for test cases and ``<ts-id>.sh`` for test suite. The tc-id and ts-id are the
22 identify of the test case or test suite. Example FTC2.sh, FTC2 is the id of the test case. Just the contents of the files determines if 
23 it is a test case or test suite so good to name the file so it is easy to see if it is a test case or a test suite.
24 A simple way to list all test cases/suite along with the description is to do ``grep ONELINE_DESCR *.sh`` in the shell.
25
26 ##Logs from containers and test cases
27 All logs from each test cases are stored under ``logs/<tc-id>/``.
28 The logs include the application.log and the container log from dfc, the container logs from each simulator and the test case log (same as the screen output).
29 In the test cases the logs are stored with a prefix so the logs can be stored at different steps during the test. All test cases contains an entry to save all logs with prefix 'END' at the end of each test case.
30 ##Execution##
31 Test cases and test suites are executed by: `` [sudo] ./<tc-id or ts-id>.sh local | remote | remote-remove | manual-container | manual-app``</br>
32 **local** - uses the dfc image pointed out by ``DFC_LOCAL_IMAGE`` in the test_env, should be the dfc image built locally in your docker registry.</br>
33 **remote** - uses the dfc image pointed out by ``DFC_REMOTE_IMAGE`` in the test_env, should be the dfc nexus image in your docker registry.</br>
34 **remote-remove** - uses the dfc image pointed out by ``DFC_REMOTE_IMAGE`` in the test_env, should be the dfc nexus image in your docker registry. Removes the nexus image and pull from remote registry.</br>
35 **manual-container** - uses dfc in a manually started container. The script will prompt you for manual starting and stopping of the container.</br>
36 **manual-app** - uses dfc app started as an external process (from eclipse etc). The script will prompt you for manual start and stop of the process.</br>
37
38 When running dfc manually, either as a container or an app the ports need to be set to map the instance id of the dfc. Most test cases start dfc with index 0, then the test case expects the ports of dfc to be mapped to the standar port number. 
39 However, if a higher instance id than 0 is used then the mapped ports need add that index to the port number (eg, if index 2 is used the dfc need to map port 8102 and 8435 instead of the standard 8100 and 8433).
40
41 ##Test case file##
42 A test case file contains a number of steps to verify a certain functionality.
43 A description of the test case should be given to the ``TC_ONELINE_DESCR`` var. The description will be printed in the test result.
44
45 The empty template for a test case files looks like this:
46
47 (Only the parts noted with < and > shall be changed.)
48
49 -----------------------------------------------------------
50 ```
51 #!/bin/bash
52
53 TC_ONELINE_DESCR="<test case description>"
54
55 . ../common/testcase_common.sh $1 $2
56
57 #### TEST BEGIN ####
58
59
60 <tests here>
61
62
63 #### TEST COMPLETE ####
64
65 store_logs          END
66
67 print_result
68
69 ```
70 -----------------------------------------------------------
71
72 The ../common/testcase_common.sh contains all functions needed for the test case file.
73
74 The following is a list of the available functions in a test case file. Please see some of the defined test case for examples.
75
76 **log_sim_settings**</br>
77 Print the env variables needed for the simulators and their setup
78
79 **clean_containers**</br>
80 Stop and remove all containers including dfc apps and simulators
81
82 **start_simulators**</br>
83 Start all simulators in the simulator group
84
85 **start_dfc <dfc-instance-id>**</br>
86 Start the dfc application. The arg shall be an integer from 0 to 5 reprenting the dfc instance to start. DFC app will get a name like 'dfc_app0' to 'dfc_app4'.
87
88 **kill_dfc  <dfc-instance-id> **</br>
89 Stop and remove the dfc app container with the instance id.
90
91 **consul_config_app <dfc-instance-id> <json-file-path>**</br>
92 Configure consul with json file with app config for a dfc instance using the dfc instance id and the json file.
93
94 **consul_config_dmaap <dfc-instance-id> <json-file-path>**</br>
95 Configure consul with json file with dmaap config for a dfc instance using the dfc instance id and the json file.
96
97 **kill_dr**</br>
98 Stop and remove the DR simulator container
99
100 **kill_drr**</br>
101 Stop and remove the DR redir simulator container
102
103 **kill_mr**</br>
104 Stop and remove the MR simulator container
105
106 **kill_sftp <sftp-instance-id>**</br>
107 Stop and remove a SFTP container with the supplied instance id (0-5).
108
109 **stop_sftp <sftp-instance-id>**</br>
110 Stop a SFTP container with the supplied instance id (0-5).
111
112 **start_sftp <sftp-instance-id>**</br>
113 Start a previously stopped SFTP container with the supplied instance id (0-5).
114
115 **kill_ftps <ftps-instance-id>**</br>
116 Stop and remove a FTPS container with the supplied instance id (0-5).
117
118 **stop_ftps <ftps-instance-id>**</br>
119 Stop a FTPS container with the supplied instance id (0-5).
120
121 **start_ftps <ftps-instance-id>**</br>
122 Start a previously stopped FTPS container with the supplied instance id (0-5).
123
124 **mr_print <vaiable-name>**</br>
125 Print a variable value from the MR simulator.
126
127 **dr_print <vaiable-name>**</br>
128 Print a varialle value from the DR simulator.
129
130 **drr_print <vaiable-name>**</br>
131 Print a variable value from the DR redir simulator.
132
133 **dfc_print <dfc-instance-id> <vaiable-name>**</br>
134 Print a variable value from an dfc instance with the supplied instance id (0-5).
135
136 **mr_read <vaiable-name>**</br>
137 Read a variable value from MR sim and send to stdout
138
139 **dr_read <vaiable-name>**</br>
140 Read a variable value from DR sim and send to stdout
141
142 **drr_read <vaiable-name>**</br>
143 Read a variable value from DR redir sim and send to stdout
144
145 **sleep_wait <sleep-time-in-sec>**</br>
146 Sleep for a number of seconds
147
148 **sleep_heartbeat <sleep-time-in-sec>**</br>
149 Sleep for a number of seconds and prints dfc heartbeat output every 30 sec
150
151 **mr_equal <variable-name> <target-value> [<timeout-in-sec>]**</br>
152 Tests if a variable value in the MR simulator is equal to a target value and and optional timeout.
153 </br>Arg: ``<variable-name> <target-value>`` - This test set pass or fail depending on if the variable is
154 equal to the targer or not.
155 </br>Arg: ``<variable-name> <target-value> <timeout-in-sec>``  - This test waits up to the timeout seconds
156 before setting pass or fail depending on if the variable value becomes equal to the target
157 value or not.
158
159 **mr_greater <variable-name> <target-value> [<timeout-in-sec>]**</br>
160 Tests if a variable value in the MR simulator is greater than a target value and and optional timeout.
161 </br>Arg: ``<variable-name> <target-value>`` - This test set pass or fail depending on if the variable is
162 greater the target or not.
163 </br>Arg: ``<variable-name> <target-value> <timeout-in-sec>``  - This test waits up to the timeout seconds
164 before setting pass or fail depending on if the variable value is greater than the target
165 value or not.
166
167 **mr_less <variable-name> <target-value> [<timeout-in-sec>]**</br>
168 Tests if a variable value in the MR simulator is less than a target value and and optional timeout.
169 </br>Arg: ``<variable-name> <target-value>`` - This test set pass or fail depending on if the variable is
170 less than the target or not.
171 </br>Arg: ``<variable-name> <target-value> <timeout-in-sec>``  - This test waits up to the timeout seconds
172 before setting pass or fail depending on if the variable value is less than the target
173 value or not.
174
175 **mr_contain_str <variable-name> <target-value> [<timeout-in-sec>]**</br>
176 Tests if a variable value in the MR simulator contains a substring target and and optional timeout.
177 </br>Arg: ``<variable-name> <target-value>`` - This test set pass or fail depending on if the variable contains
178 the target substring or not.
179 </br>Arg: ``<variable-name> <target-value> <timeout-in-sec>``  - This test waits up to the timeout seconds
180 before setting pass or fail depending on if the variable value contains the target
181 substring or not.
182
183 **dr_equal <variable-name> <target-value> [<timeout-in-sec>]**</br>
184 Tests if a variable value in the DR simulator is equal to a target value and and optional timeout.
185 </br>Arg: ``<variable-name> <target-value>`` - This test set pass or fail depending on if the variable is
186 equal to the target or not.
187 </br>Arg: ``<variable-name> <target-value> <timeout-in-sec>``  - This test waits up to the timeout seconds
188 before setting pass or fail depending on if the variable value becomes equal to the target
189 value or not.
190
191 **dr_greater <variable-name> <target-value> [<timeout-in-sec>]**</br>
192 Tests if a variable value in the DR simulator is greater than a target value and and optional timeout.
193 </br>Arg: ``<variable-name> <target-value>`` - This test set pass or fail depending on if the variable is
194 greater the target or not.
195 </br>Arg: ``<variable-name> <target-value> <timeout-in-sec>``  - This test waits up to the timeout seconds
196 before setting pass or fail depending on if the variable value is greater than the target
197 value or not.
198
199 **dr_less <variable-name> <target-value> [<timeout-in-sec>]**</br>
200 Tests if a variable value in the DR simulator is less than a target value and and optional timeout.
201 </br>Arg: ``<variable-name> <target-value>`` - This test set pass or fail depending on if the variable is
202 less than the target or not.
203 </br>Arg: ``<variable-name> <target-value> <timeout-in-sec>``  - This test waits up to the timeout seconds
204 before setting pass or fail depending on if the variable value is less than the target
205 value or not.
206
207 **dr_contain_str <variable-name> <target-value> [<timeout-in-sec>]**</br>
208 Tests if a variable value in the DR simulator contains a substring target and and optional timeout.
209 </br>Arg: ``<variable-name> <target-value>`` - This test set pass or fail depending on if the variable contains
210 the target substring or not.
211 </br>Arg: ``<variable-name> <target-value> <timeout-in-sec>``  - This test waits up to the timeout seconds
212 before setting pass or fail depending on if the variable value contains the target
213 substring or not.
214
215 **drr_equal <variable-name> <target-value> [<timeout-in-sec>]**</br>
216 Tests if a variable value in the DR Redir simulator is equal to a target value and and optional timeout.
217 </br>Arg: ``<variable-name> <target-value>`` - This test set pass or fail depending on if the variable is
218 equal to the target or not.
219 </br>Arg: ``<variable-name> <target-value> <timeout-in-sec>``  - This test waits up to the timeout seconds
220 before setting pass or fail depending on if the variable value becomes equal to the target
221 value or not.
222
223 **drr_greater <variable-name> <target-value> [<timeout-in-sec>]**</br>
224 Tests if a variable value in the DR Redir simulator is greater than a target value and and optional timeout.
225 </br>Arg: ``<variable-name> <target-value>`` - This test set pass or fail depending on if the variable is
226 greater the target or not.
227 </br>Arg: ``<variable-name> <target-value> <timeout-in-sec>``  - This test waits up to the timeout seconds
228 before setting pass or fail depending on if the variable value is greater than the target
229 value or not.
230
231 **drr_less <variable-name> <target-value> [<timeout-in-sec>]**</br>
232 Tests if a variable value in the DR Redir simulator is less than a target value and and optional timeout.
233 </br>Arg: ``<variable-name> <target-value>`` - This test set pass or fail depending on if the variable is
234 less than the target or not.
235 </br>Arg: ``<variable-name> <target-value> <timeout-in-sec>``  - This test waits up to the timeout seconds
236 before setting pass or fail depending on if the variable value is less than the target
237 value or not.
238
239 **drr_contain_str <variable-name> <target-value> [<timeout-in-sec>]**</br>
240 Tests if a variable value in the DR Redir simulator contains a substring target and and optional timeout.
241 </br>Arg: ``<variable-name> <target-value>`` - This test set pass or fail depending on if the variable contains
242 the target substring or not.
243 </br>Arg: ``<variable-name> <target-value> <timeout-in-sec>``  - This test waits up to the timeout seconds
244 before setting pass or fail depending on if the variable value contains the target
245 substring or not.
246
247 **dfc_contain_str <variable-name> <substring-in-quotes>**</br>
248 Test is a variable in the DFC contains a substring.
249
250 **store_logs <log-prefix>**</br>
251 Store all dfc app and simulators log to the test case log dir. All logs gets a prefix to
252 separate logs stored at different steps in the test script.
253 If logs need to be stored in several locations, use different prefix to easily identify the location
254 when the logs where taken.
255
256 **check_dfc_log**</br>
257 Check the dfc application log for WARN and ERR messages and print the count.
258
259 **print_result**</br>
260 Print the test result. Only once at the very end of the script.
261
262 **print_all**</br>
263 Print all variables from the simulators and the dfc heartbeat.
264
265 In addition, comment in the file can be added using the normal comment sign in bash '#'.
266 Comments that shall be visible on the screen as well as in the test case log, use ``echo "<msg>"``.
267
268 ##Test suite files##
269 A test suite file contains one or more test cases to run in sequence.
270 A description of the test case should be given to the ``TS_ONELINE_DESCR`` var. The description will be printed in the test result.
271
272 The empty template for a test suite files looks like this:
273
274 (Only the parts noted with ``<`` and ``>`` shall be changed.)
275
276 -----------------------------------------------------------
277 ```
278 #!/bin/bash
279
280 TS_ONELINE_DESCR="<test-suite-description>"
281
282 . ../common/testsuite_common.sh
283
284 suite_setup
285
286 ############# TEST CASES #################
287
288 run_tc <tc-id or ts-id>.sh $1 $2
289 ...
290 ...
291
292 ##########################################
293
294 suite_complete
295
296
297 ```
298 -----------------------------------------------------------
299
300 The ../common/testsuite_common.sh contains all functions needed for a test suite file.
301
302 The following is a list of the available functions in a test case file. Please see a existing test suite for examples.
303
304 **suite_setup**</br>
305 Sets up the test suite and print out a heading.
306
307 **run_tc <tc-script> <$1 from test suite script> <$2 from test suite script>**</br>
308 Execute a test case with arg from test suite script
309
310 **suite_complete**</br>
311 Print out the overall result of the executed test cases.