Skip to content

Commit

Permalink
Fiddling with test scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
whyscream committed Jul 5, 2024
1 parent 25eb6a8 commit 9d7793e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
5 changes: 3 additions & 2 deletions test_config_syntax.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
# The configuration file is validated using the logstash --config.test_and_exit command in a docker container.
#

set -eux
set -eu

LOGSTASH_VERSION=8.14.1

docker run --rm -it \
docker run \
--rm \
--volume "$(pwd)"/postfix.grok:/etc/logstash/patterns.d/postfix.grok \
--volume "$(pwd)"/50-filter-postfix.conf:/usr/share/logstash/pipeline/50-filter-postfix.conf \
logstash:"$LOGSTASH_VERSION" \
Expand Down
9 changes: 7 additions & 2 deletions test_grok_patterns.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# The patterns are tested by running the test suite (in test/test.rb and test/*.yaml)
# against the patterns in the postfix.grok file in a docker container.
#
set -eux
set -eu

DOCKERIMAGE="postfix-grok-patterns-runtests"
VOLUMEPATH="/runtests"
Expand All @@ -18,4 +18,9 @@ FROM ruby:slim
RUN gem install jls-grok minitest
EOF

docker run --volume "$(pwd)":"${VOLUMEPATH}" --workdir ${VOLUMEPATH} ${DOCKERIMAGE} sh -c "ruby test/test.rb"
docker run \
--rm \
--volume "$(pwd)":"${VOLUMEPATH}" \
--workdir ${VOLUMEPATH} \
${DOCKERIMAGE} \
sh -c "ruby test/test.rb"
14 changes: 9 additions & 5 deletions test_pipeline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@
# sends a test logline through the pipeline and checks the results.
#

set -eux
set -eu

LOGSTASH_VERSION=8.14.1

INPUT=$(mktemp tmp.logstash.in.XXXXX)
OUTPUT=$(mktemp tmp.logstash.out.XXXXX)
PIPELINE=$(mktemp tmp.logstash.pipeline.XXXXX)

perform_cleanup() {
echo Cleaning up
test -n "CONTAINER_ID" && docker stop --time 1 "$CONTAINER_ID" > /dev/null
rm -f "$INPUT" "$OUTPUT" "$PIPELINE"
}
trap perform_cleanup INT TERM

echo Preparing input data
echo "postfix/smtp[123]: 7EE668039: to=<[email protected]>, 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"

Expand Down Expand Up @@ -61,8 +68,6 @@ until test -s "$OUTPUT"; do
done
echo

docker stop --time 1 "$CONTAINER_ID" > /dev/null

if test "$(jq .tags[0] "$OUTPUT")" = '"_grok_postfix_success"'; then
echo Grok processing successful!
jq . "$OUTPUT"
Expand All @@ -72,7 +77,6 @@ else
exit 1
fi

echo Cleaning up
rm -f "$INPUT" "$OUTPUT" "$PIPELINE"
perform_cleanup

echo Done

0 comments on commit 9d7793e

Please sign in to comment.