Skip to content

Commit

Permalink
add test to cover entrypoint
Browse files Browse the repository at this point in the history
Signed-off-by: Furkan Türkal <[email protected]>
  • Loading branch information
Dentrax committed Mar 20, 2024
1 parent 34553ac commit d8657d8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
Binary file added APKINDEX.tar.gz
Binary file not shown.
46 changes: 44 additions & 2 deletions confluent-kafka.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ test:
- zookeeper
- busybox
- netcat-openbsd
- confluent-common-docker
- confluent-common-docker-ub
- confluent-common-docker-base
- confluent-docker-utils
- confluent-kafka-images-kafka
pipeline:
- runs: |
KAFKA_DIR=/usr/lib/kafka
Expand All @@ -96,7 +101,7 @@ test:
"${KAFKA_DIR}/config/zookeeper.properties" > "${KAFKA_DIR}/logs/zookeeper.out" 2> \
"${KAFKA_DIR}/logs/zookeeper.err" < /dev/null &
ZOO_PID=$!
sleep 10
sleep 5
# We have more test cases in the image, but this is a simple quick-win to check if the service is running.
# That's becasue Zookeeper stops printing logs after it prints the Banner on the CI, but works fine in the image and locally.
Expand All @@ -105,11 +110,48 @@ test:
echo "Starting Kafka..."
nohup "${KAFKA_DIR}/bin/kafka-server-start.sh" "${KAFKA_DIR}/config/server.properties" > "${KAFKA_DIR}/logs/kafka.out" 2> "${KAFKA_DIR}/logs/kafka.err" < /dev/null &
KAFKA_PID=$!
sleep 10
sleep 5
# Kafka doesn't print logs on the CI, but works fine in the image test and locally.
# grep "Controller 0 connected" "${KAFKA_DIR}/logs/controller.log" > /dev/null || { cat "${KAFKA_DIR}/logs/controller.log"; echo "Kafka log entry not found"; exit 1; }
# Cleanup
kill $KAFKA_PID
kill $ZOO_PID
- runs: |
export COMPONENT="kafka" KAFKA_ZOOKEEPER_CONNECT="127.0.0.1:2888" KAFKA_ADVERTISED_LISTENERS="PLAINTEXT://localhost:9092" CLUSTER_ID="" CUB_CLASSPATH="/usr/share/java/kafka/*:/usr/share/java/cp-base-new/*:/usr/share/java/zookeeper/*:/usr/share/java/confluent-common-docker/*"
set +e
echo "Starting entrypoint..."
logs=$(timeout 5 /etc/confluent/docker/run 2>&1)
set -e
# Use assert_true for conditions that should be true
assert_true() {
local assert="$1"
if ! echo "$logs" | grep -q "$assert"; then
echo "Did not find '$assert' in logs"
echo "$logs"
exit 1
fi
}
# Use assert_false for conditions that should be false
assert_false() {
local assert="$1"
if echo "$logs" | grep -q "$assert"; then
echo "Found '$assert' in logs"
echo "$logs"
exit 1
fi
}
assert_true "Configuring"
assert_true "Running preflight checks"
# We couldn't run zookeeper in the CI for some reason so
# package keep trying to connect to it as an expected case.
# More detailed tests in the image.
assert_true "Check if Zookeeper is healthy"
# Ensure all required Java libs are available in the classpath
assert_false "Could not find or load main class"
assert_false "java.lang.ClassNotFoundException"

0 comments on commit d8657d8

Please sign in to comment.