Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
edenhill committed Jan 4, 2021
1 parent 2aa9dea commit 86a2f79
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Makefile
Expand Up @@ -26,6 +26,9 @@ install-man:

clean: bin-clean

test:
$(MAKE) -C tests

TAGS: .PHONY
@(if which etags >/dev/null 2>&1 ; then \
echo "Using etags to generate $@" ; \
Expand Down
10 changes: 10 additions & 0 deletions tests/0000-unit.sh
@@ -0,0 +1,10 @@
#!/bin/bash
#

# Run builtin unittests
#

set -e
source helpers.sh

$KAFKACAT -U
50 changes: 50 additions & 0 deletions tests/0001-exit_eof.sh
@@ -0,0 +1,50 @@
#!/bin/bash
#

set -e

source helpers.sh


#
# Verify that -e (exit on eof) works on both low-level and high-level consumer
#


topic=$(make_topic_name)

# Produce some messages to topic
info "Priming producer for $topic"
seq 1 10 | $KAFKACAT -t $topic


# Legacy: Consume messages without -e, should timeout.
info "Legacy consumer without -e"
timeout 5 $KAFKACAT -t $topic -o beginning && \
FAIL "Legacy consumer without -e should have timed out"


# Balanced: Consume messages without -e, should timeout.
info "Balanced consumer without -e"
timeout 10 $KAFKACAT -G $topic -o beginning $topic && \
"Balanced consumer without -e should have timed out"


# Legacy: Consume messages with -e, must not timeout
info "Legacy consumer with -e"
timeout 5 $KAFKACAT -t $topic -o beginning -e || \
FAIL "Legacy consumer with -e timed out"


# Balanced: Consume messages without -e, should timeout.
# FIXME: -e and -G doesn't currently work.
if false; then
info "Balanced consumer with -e"
timeout 10 $KAFKACAT -G ${topic}_new -o beginning -e $topic || \
FAIL "Balanced consumer with -e timed out"
fi

PASS



62 changes: 62 additions & 0 deletions tests/0002-delim.sh
@@ -0,0 +1,62 @@
#!/bin/bash
#

set -e
source helpers.sh


#
# Verify that single and multi-byte delimiters work.
#


topic=$(make_topic_name)



# Multi-byte delimiters, partition 0

echo -n "Key1;KeyDel;Value1:MyDilemma::MyDilemma:;KeyDel;Value2:MyDilemma:Key3;KeyDel;:MyDilemma:Value4" |
$KAFKACAT -t $topic -p 0 -K ';KeyDel;' -D ':MyDilemma:' -Z


output=$($KAFKACAT -C -t $topic -p 0 -o beginning -e -J |
jq -r '.key + "=" + .payload')

exp="Key1=Value1
=Value2
Key3=
=Value4"

if [[ $output != $exp ]]; then
echo "FAIL: Expected '$exp', not '$output'"
exit 1
fi


#
# Single-byte delimiters, partition 1
#

echo "The First;Message1
Is The;
;Greatest
For sure" |
$KAFKACAT -t $topic -p 1 -K ';' -Z


output=$($KAFKACAT -C -t $topic -p 1 -o beginning -e -J |
jq -r '.key + "=" + .payload')

exp="The First=Message1
Is The=
=Greatest
=For sure"

if [[ $output != $exp ]]; then
echo "FAIL: Expected '$exp', not '$output'"
exit 1
fi


11 changes: 11 additions & 0 deletions tests/Makefile
@@ -0,0 +1,11 @@


all: run


run:
@(for test in 0[0-9][0-9][0-9]*.sh ; do \
( ./$$test && \
echo "=== Test $$test PASSED ===" ) || \
(echo "=== Test $$test FAILED ===" ; exit 1) ;\
done)
6 changes: 6 additions & 0 deletions tests/README.md
@@ -0,0 +1,6 @@
These tests assume a cluster is running and the bootstrap.servers
is set in the $BROKERS environment variable.

The cluster is assumed to have auto topic creation enabled with
a default partition count of at least 3.

37 changes: 37 additions & 0 deletions tests/helpers.sh
@@ -0,0 +1,37 @@
set -e

CLR_BGRED="\033[37;41m"
CLR_BGGREEN="\033[37;42m"
CLR_INFO="\033[34m"
CLR="\033[0m"

if [[ -z "$BROKERS" ]]; then
echo -e "${CLR_BGRED}kafkacat tests requires \$BROKERS to be set${CLR}"
exit 1
fi

KAFKACAT="../kafkacat -b $BROKERS"
TEST_NAME=$(basename $0 | sed -e 's/\.sh$//')

function make_topic_name {
local name=$1
echo "kafkacat_test_$$_${RANDOM}_${TEST_NAME}name"
}



function info {
local str=$1
echo -e "${CLR_INFO}${TEST_NAME} | $str${CLR}"
}

function FAIL {
local str=$1
echo -e "${CLR_BGRED}${TEST_NAME} | TEST FAILED: $str${CLR}"
exit 1
}

function PASS {
local str=$1
echo -e "${CLR_BGGREEN}${TEST_NAME} | TEST PASSED: $str${CLR}"
}

0 comments on commit 86a2f79

Please sign in to comment.