forked from gaspaio/logstash-tester
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logstash-tester.sh
executable file
·149 lines (126 loc) · 4.09 KB
/
logstash-tester.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
#!/bin/bash
usage() {
echo "
Logstash Tester - Unit-testing for Logstash configuration fields
Usage:
./logstash-tester.sh [-chp] -d path [test_target]
- 'path' is the base directory for your config files and test cases.
- 'test_target' takes one of three possible values:
'patterns', 'filters', 'all'.
It tells logstash-tester to runs pattern tests only,
filter tests only or both, respectively. The default is 'all'.
See examples for ... hum ... examples.
Options:
-d
Root directory for all your logstash config and test files.
It is not optional and it should have a specific structure.
See documentation for details or the 'example' directory in the
repository root.
-c
Don't check the syntax of logstash configuration before running tests.
The default is to execute 'logstash --configtest -f <config-dir> '
before running the tests.
-p
The filter tests subdirectory, inside the main test case directory.
This allows you to run a subset of tests.
-h
This text.
Examples
./logstash-tester.sh -d example
The simplest command line form. Run all tests, root dir for config and
test files is 'example'.
./logstash-tester.sh -d example -p syslog filters
Run the subset of filter tests located in the 'syslog' directory
(./test/filters/syslog).
More info on the project repository:
https://github.com/gaspaio/logstash-tester
"
}
error() {
echo "$* See help (-h) for details."
exit 1
}
run_docker() {
action=$1
configtest=$2
if ! hash docker 2> /dev/null; then
error "Can't find the Docker executable. Did you install it?"
fi
rootdir=`dirname $0`
echo "====> Build docker image for test"
docker build -t logstash-tester \
--build-arg LST=$rootdir \
--build-arg FILTER_CONFIG=$3 \
--build-arg PATTERN_CONFIG=$4 \
--build-arg FILTER_TESTS=$5 \
--build-arg PATTERN_TESTS=$6 \
-f $rootdir/Dockerfile .
echo "====> Run test in docker container"
docker run --rm -it logstash-tester /test/run-tests.sh $action $configtest
}
# Default values
action=all
configtest=y
filter_test_path=
datadir=
while getopts ":d:p:ch" opt; do
case $opt in
d)
if [[ -d $OPTARG ]]; then
datadir=$OPTARG
else
error "'$OPTARG' is not a valid directory."
fi
;;
c)
configtest=n
;;
p)
filter_test_path=$OPTARG
;;
h)
usage
exit 0
;;
:)
error "Option -$OPTARG requires an argument."
;;
\?)
error "Invalid option -$OPTARG."
;;
esac
done
# Handle remaining positional arguments
shift $((OPTIND-1))
if [[ -z $@ ]]; then
action=all
elif [[ $@ != 'all' && $@ != 'filters' && $@ != 'patterns' ]]; then
error "'$@' is not a valid action."
else
action=$@
fi
# Handle compulsory arguments
if [[ -z $datadir ]]; then
error "You must define a root dir for your config and test files."
fi
# Validate directories
docker_filter_config=$datadir/config/conf.d
if [[ ! -d $docker_filter_config ]]; then
error "The filter config directory '$docker_filter_config' does not exist."
fi
docker_pattern_config=$datadir/config/patterns
if [[ ! -d $docker_pattern_config ]]; then
error "The patterns directory '$docker_pattern_config' does not exist."
fi
docker_filter_test=$datadir/test/filters
if [[ ! -z $filter_test_path ]]; then
docker_filter_test=$docker_filter_test/$filter_test_path
fi
if [[ ! -d $docker_filter_test ]]; then
error "The filter tests directory '$docker_filter_test' does not exist."
fi
docker_pattern_test=$datadir/test/patterns
if [[ ! -d $docker_pattern_test ]]; then
error "The patterns tests directory '$docker_pattern_test' does not exist."
fi
run_docker $action $configtest $docker_filter_config $docker_pattern_config $docker_filter_test $docker_pattern_test