Skip to content

Commit 079bcda

Browse files
committed
Deduplicator - Add tests
1 parent 390e1c6 commit 079bcda

3 files changed

Lines changed: 76 additions & 0 deletions

File tree

modules/deduplicator/tests/test.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
3+
function exit_with_error {
4+
pkill logger
5+
pkill logreplay
6+
pkill deduplicator
7+
exit 1
8+
}
9+
10+
function process_started {
11+
pid=$1
12+
if ! ps -p $pid > /dev/null
13+
then
14+
echo "Failed to start process"
15+
exit_with_error
16+
fi
17+
}
18+
19+
data_path="$(dirname "$0")/testsData/"
20+
deduplicator=$1
21+
22+
set -e
23+
trap 'echo "Command \"$BASH_COMMAND\" failed!"; exit_with_error' ERR
24+
for input_file in $data_path/inputs/*; do
25+
index=$(echo "$input_file" | grep -o '[0-9]\+')
26+
echo "Running test $index"
27+
28+
res_file="/tmp/res"
29+
logger -i "u:deduplicator" -w $res_file &
30+
logger_pid=$!
31+
sleep 0.1
32+
33+
process_started $logger_pid
34+
35+
$deduplicator \
36+
-i "u:din,u:deduplicator" &
37+
38+
detector_pid=$!
39+
sleep 0.1
40+
process_started $detector_pid
41+
42+
logreplay -i "u:din" -f "$data_path/inputs/input$index.csv" 2>/dev/null &
43+
sleep 0.1
44+
process_started $!
45+
46+
wait $logger_pid
47+
wait $detector_pid
48+
49+
if [ -f "$res_file" ]; then
50+
if ! cmp -s "$data_path/results/res$index.csv" "$res_file"; then
51+
echo "Files results/res$index.csv and $res_file are not equal"
52+
exit_with_error
53+
fi
54+
else
55+
echo "File $res_file not found"
56+
exit_with_error
57+
fi
58+
done
59+
60+
echo "All tests passed"
61+
exit 0
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ipaddr SRC_IP, ipaddr DST_IP, uint16 SRC_PORT, uint16 DST_PORT, uint8 PROTOCOL, uint64 LINK_BIT_FIELD, time TIME_LAST
2+
154.175.219.8,155.175.219.8,123,123,6,10,2020-01-01T00:00:01Z
3+
54.175.29.123,54.175.219.24,123,80,6,10,2020-01-01T00:00:02Z
4+
54.175.21.66,54.175.219.77,443,22,6,10,2020-01-01T00:00:03Z
5+
54.175.3.17,54.175.219.99,8080,53,17,10,2020-01-01T00:00:04Z
6+
154.175.219.8,155.175.219.8,123,123,6,10,2020-01-01T00:00:01Z
7+
154.175.219.8,155.175.219.8,123,123,6,11,2020-01-01T00:00:01Z
8+
154.175.219.8,155.175.219.8,123,123,6,10,2020-01-01T00:00:01Z
9+
154.175.219.8,155.175.219.8,123,123,6,11,2020-01-01T00:00:01Z
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
155.175.219.8,154.175.219.8,10,2020-01-01T00:00:01.000000,123,123,6
2+
54.175.219.24,54.175.29.123,10,2020-01-01T00:00:02.000000,80,123,6
3+
54.175.219.77,54.175.21.66,10,2020-01-01T00:00:03.000000,22,443,6
4+
54.175.219.99,54.175.3.17,10,2020-01-01T00:00:04.000000,53,8080,17
5+
155.175.219.8,154.175.219.8,10,2020-01-01T00:00:01.000000,123,123,6
6+
155.175.219.8,154.175.219.8,10,2020-01-01T00:00:01.000000,123,123,6

0 commit comments

Comments
 (0)