-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathRunBehaveTests.sh
More file actions
executable file
·213 lines (185 loc) · 6.76 KB
/
RunBehaveTests.sh
File metadata and controls
executable file
·213 lines (185 loc) · 6.76 KB
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
#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
die()
{
local _ret="${2:-1}"
test "${_PRINT_HELP:-no}" = yes && print_help >&2
echo "$1" >&2
exit "${_ret}"
}
_positionals=()
_arg_image_tag_prefix=
_arg_tags_to_exclude=
_arg_parallel_processes=3
print_help()
{
printf '%s\n' "Runs the provided behave tests in a containerized environment"
printf 'Usage: %s [--image-tag-prefix <arg>] [-h|--help] <minifi_version> <tags_to_run> ...\n' "$0"
printf '\t%s\n' "<minifi_version>: the version of minifi"
printf '\t%s\n' "<tags_to_run>: comma-separated list of tags to include, e.g: CORE,ENABLE_KAFKA,ENABLE_SPLUNK"
printf '\t%s\n' "--tags_to_exclude: optional comma-separated list of tags that should be skipped (default: none)"
printf '\t%s\n' "--image-tag-prefix: optional prefix to the docker tag (default: none)"
printf '\t%s\n' "--parallel_processes: optional argument that specifies the number of parallel processes that can be executed simultaneously (default: 3)"
printf '\t%s\n' "--fips: enables FIPS mode by default"
printf '\t%s\n' "-h, --help: Prints help"
}
parse_commandline()
{
_positionals_count=0
_arg_fips=false # Default to false
while test $# -gt 0
do
_key="$1"
case "$_key" in
--image-tag-prefix)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
_arg_image_tag_prefix="$2"
shift
;;
--image-tag-prefix=*)
_arg_image_tag_prefix="${_key##--image-tag-prefix=}"
;;
--tags_to_exclude)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
_arg_tags_to_exclude="$2"
shift
;;
--tags_to_exclude=*)
_arg_tags_to_exclude="${_key##--tags_to_exclude=}"
;;
--parallel_processes)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
_arg_parallel_processes="$2"
shift
;;
--parallel_processes=*)
_arg_parallel_processes="${_key##--parallel_processes=}"
;;
--fips)
_arg_fips=true # Set boolean flag to true when argument is present
;;
-h|--help)
print_help
exit 0
;;
-h*)
print_help
exit 0
;;
*)
_last_positional="$1"
_positionals+=("$_last_positional")
_positionals_count=$((_positionals_count + 1))
;;
esac
shift
done
}
handle_passed_args_count()
{
local _required_args_string="'minifi_version' and 'tags_to_run'"
test "${_positionals_count}" -ge 2 || _PRINT_HELP=yes die "FATAL ERROR: Not enough positional arguments - we require at least 2 (namely: $_required_args_string), but got only ${_positionals_count}." 1
}
assign_positional_args()
{
local _positional_name _shift_for=$1
_positional_names="_arg_minifi_version _arg_tags_to_run "
shift "$_shift_for"
for _positional_name in ${_positional_names}
do
test $# -gt 0 || break
eval "$_positional_name=\${1}" || die "Error during argument parsing." 1
shift
done
}
parse_commandline "$@"
handle_passed_args_count
assign_positional_args 1 "${_positionals[@]}"
docker_dir="$( cd "${0%/*}" && pwd )"
# shellcheck disable=SC2154
export MINIFI_VERSION=${_arg_minifi_version}
if test -z "$_arg_image_tag_prefix"
then
export MINIFI_TAG_PREFIX=""
else
export MINIFI_TAG_PREFIX=${_arg_image_tag_prefix}-
fi
if [ "$_arg_fips" = true ]; then
export MINIFI_FIPS="true"
else
export MINIFI_FIPS="false"
fi
# Create virtual environment for testing
if [[ ! -d ./behave_venv ]]; then
echo "Creating virtual environment in ./behave_venv" 1>&2
virtualenv --python=python3 ./behave_venv
fi
echo "Activating virtual environment..." 1>&2
# shellcheck disable=SC1091
. ./behave_venv/bin/activate
pip install --trusted-host pypi.python.org --upgrade pip setuptools
# Install test dependencies
echo "Installing test dependencies..." 1>&2
# hint include/library paths if homewbrew is in use
if brew list 2> /dev/null | grep openssl > /dev/null 2>&1; then
echo "Using homebrew paths for openssl" 1>&2
LDFLAGS="-L$(brew --prefix openssl@1.1)/lib"
export LDFLAGS
CFLAGS="-I$(brew --prefix openssl@1.1)/include"
export CFLAGS
SWIG_FEATURES="-cpperraswarn -includeall -I$(brew --prefix openssl@1.1)/include"
export SWIG_FEATURES
fi
if ! command swig -version &> /dev/null; then
echo "Swig could not be found on your system (dependency of m2crypto python library). Please install swig to continue."
exit 1
fi
pip install -e "${docker_dir}/../behave_framework"
export TMPDIR="/tmp/behavex_ci_${RANDOM}"
mkdir -p "$TMPDIR"
export TEMP="$TMPDIR/temp"
export LOGS="$TMPDIR/logs"
BEHAVE_OPTS=(--show-progress-bar --logging-level INFO --parallel-processes "${_arg_parallel_processes}" --parallel-scheme feature -o "${PWD}/behavex_output_modular" -t "${_arg_tags_to_run}")
if ! test -z "${_arg_tags_to_exclude}"
then
IFS=','
read -ra splits <<< "${_arg_tags_to_exclude}"
for split in "${splits[@]}"
do
BEHAVE_OPTS=("${BEHAVE_OPTS[@]}" -t "~${split}")
done
fi
echo "${BEHAVE_OPTS[@]}"
exec \
behavex "${BEHAVE_OPTS[@]}" \
"${docker_dir}/../extensions/standard-processors/tests/features" \
"${docker_dir}/../extensions/aws/tests/features" \
"${docker_dir}/../extensions/azure/tests/features" \
"${docker_dir}/../extensions/sql/tests/features" \
"${docker_dir}/../extensions/llamacpp/tests/features" \
"${docker_dir}/../extensions/opc/tests/features" \
"${docker_dir}/../extensions/kafka/tests/features" \
"${docker_dir}/../extensions/couchbase/tests/features" \
"${docker_dir}/../extensions/elasticsearch/tests/features" \
"${docker_dir}/../extensions/splunk/tests/features" \
"${docker_dir}/../extensions/gcp/tests/features" \
"${docker_dir}/../extensions/grafana-loki/tests/features" \
"${docker_dir}/../extensions/lua/tests/features/" \
"${docker_dir}/../extensions/civetweb/tests/features/" \
"${docker_dir}/../extensions/mqtt/tests/features/" \
"${docker_dir}/../extensions/prometheus/tests/features/" \
"${docker_dir}/../extensions/python/tests/features/"