Browse Source

Add simple new "logstash-basics" test

Tianon Gravi 9 năm trước cách đây
mục cha
commit
602c9eb427
2 tập tin đã thay đổi với 80 bổ sung0 xóa
  1. 3 0
      test/config.sh
  2. 77 0
      test/tests/logstash-basics/run.sh

+ 3 - 0
test/config.sh

@@ -86,6 +86,9 @@ imageTests+=(
 	[julia]='
 		julia-hello-world
 	'
+	[logstash]='
+		logstash-basics
+	'
 	[memcached]='
 	'
 	[mongo]='

+ 77 - 0
test/tests/logstash-basics/run.sh

@@ -0,0 +1,77 @@
+#!/bin/bash
+
+[ "$DEBUG" ] && set -x
+
+set -eo pipefail
+
+dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
+
+image="$1"
+
+# Use the image being tested as our client image since it should already have curl
+clientImage="$image"
+
+# input via HTTP (default port 0.0.0.0:8080)
+# output via stdout, newline-delimited nothing-but-the-message
+config='
+	input {
+		http {
+		}
+	}
+	output {
+		stdout {
+			codec => line {
+				format => "%{message}"
+			}
+		}
+	}
+'
+
+# Create an instance of the container-under-test
+cid="$(docker run -d "$image" -e "$config")"
+trap "docker rm -vf $cid > /dev/null" EXIT
+
+_request() {
+	# https://github.com/docker/docker/issues/14203#issuecomment-129865960 (DOCKER_FIX)
+	docker run --rm --link "$cid":logstash \
+		-e DOCKER_FIX='                                        ' \
+		"$clientImage" curl -fs "$@" "http://logstash:8080"
+}
+
+_trimmed() {
+	_request "$@" | sed -r 's/^[[:space:]]+|[[:space:]]+$//g'
+}
+
+_req-comp() {
+	local expected="$1"; shift
+	response="$(_trimmed "$@")"
+	[ "$response" = "$expected" ]
+}
+
+_req-exit() {
+	local expectedRet="$1"; shift
+	[ "$(_request "$@" --output /dev/null || echo "$?")" = "$expectedRet" ]
+}
+
+_req-msg() {
+	local msg="$1"; shift
+	_req-comp 'ok' --data "$msg"
+	# use "retry.sh" to give logstash just a tiny bit of time to actually print the message to stdout
+	. "$dir/../../retry.sh" --tries 3 --sleep 0.5 '
+		logLine="$(docker logs --tail=1 "$cid")";
+		[ "$logLine" = "$msg" ];
+	'
+}
+
+# Make sure our container is listening
+. "$dir/../../retry.sh" '! _req-exit 7' # "Failed to connect to host."
+
+for msg in \
+	'hi' \
+	"hello $RANDOM world" \
+	"hello $RANDOM world" \
+	"hello $RANDOM world" \
+	'bye' \
+; do
+	_req-msg "$msg"
+done