Skip to content

Commit 9d7793e

Browse files
committed
Fiddling with test scripts
1 parent 25eb6a8 commit 9d7793e

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

test_config_syntax.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
# The configuration file is validated using the logstash --config.test_and_exit command in a docker container.
77
#
88

9-
set -eux
9+
set -eu
1010

1111
LOGSTASH_VERSION=8.14.1
1212

13-
docker run --rm -it \
13+
docker run \
14+
--rm \
1415
--volume "$(pwd)"/postfix.grok:/etc/logstash/patterns.d/postfix.grok \
1516
--volume "$(pwd)"/50-filter-postfix.conf:/usr/share/logstash/pipeline/50-filter-postfix.conf \
1617
logstash:"$LOGSTASH_VERSION" \

test_grok_patterns.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# The patterns are tested by running the test suite (in test/test.rb and test/*.yaml)
77
# against the patterns in the postfix.grok file in a docker container.
88
#
9-
set -eux
9+
set -eu
1010

1111
DOCKERIMAGE="postfix-grok-patterns-runtests"
1212
VOLUMEPATH="/runtests"
@@ -18,4 +18,9 @@ FROM ruby:slim
1818
RUN gem install jls-grok minitest
1919
EOF
2020

21-
docker run --volume "$(pwd)":"${VOLUMEPATH}" --workdir ${VOLUMEPATH} ${DOCKERIMAGE} sh -c "ruby test/test.rb"
21+
docker run \
22+
--rm \
23+
--volume "$(pwd)":"${VOLUMEPATH}" \
24+
--workdir ${VOLUMEPATH} \
25+
${DOCKERIMAGE} \
26+
sh -c "ruby test/test.rb"

test_pipeline.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,21 @@
77
# sends a test logline through the pipeline and checks the results.
88
#
99

10-
set -eux
10+
set -eu
1111

1212
LOGSTASH_VERSION=8.14.1
1313

1414
INPUT=$(mktemp tmp.logstash.in.XXXXX)
1515
OUTPUT=$(mktemp tmp.logstash.out.XXXXX)
1616
PIPELINE=$(mktemp tmp.logstash.pipeline.XXXXX)
1717

18+
perform_cleanup() {
19+
echo Cleaning up
20+
test -n "CONTAINER_ID" && docker stop --time 1 "$CONTAINER_ID" > /dev/null
21+
rm -f "$INPUT" "$OUTPUT" "$PIPELINE"
22+
}
23+
trap perform_cleanup INT TERM
24+
1825
echo Preparing input data
1926
echo "postfix/smtp[123]: 7EE668039: to=<admin@example.com>, relay=127.0.0.1[127.0.0.1]:2525, delay=3.6, delays=0.2/0.02/0.04/3.3, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 153053D)" > "$INPUT"
2027

@@ -61,8 +68,6 @@ until test -s "$OUTPUT"; do
6168
done
6269
echo
6370

64-
docker stop --time 1 "$CONTAINER_ID" > /dev/null
65-
6671
if test "$(jq .tags[0] "$OUTPUT")" = '"_grok_postfix_success"'; then
6772
echo Grok processing successful!
6873
jq . "$OUTPUT"
@@ -72,7 +77,6 @@ else
7277
exit 1
7378
fi
7479

75-
echo Cleaning up
76-
rm -f "$INPUT" "$OUTPUT" "$PIPELINE"
80+
perform_cleanup
7781

7882
echo Done

0 commit comments

Comments
 (0)