Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for tcp.echo, tls.echo and http.kafka.sync examples #126

Merged
merged 6 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Test Examples

on:
pull_request:
workflow_dispatch:

jobs:
test-tcp-echo:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Create k8s Kind Cluster
uses: helm/kind-action@v1
- name: Setup
working-directory: tcp.echo
run: ./setup.sh
- name: Execute Test
working-directory: tcp.echo
run: |
set -o pipefail
./test.sh | tee $GITHUB_STEP_SUMMARY
- name: Teardown
if: always()
working-directory: tcp.echo
run: ./teardown.sh

test-tls-echo:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Create k8s Kind Cluster
uses: helm/kind-action@v1
- name: Setup
working-directory: tls.echo
run: ./setup.sh
- name: Execute Test
working-directory: tls.echo
run: |
set -o pipefail
./test.sh | tee $GITHUB_STEP_SUMMARY
- name: Teardown
if: always()
working-directory: tls.echo
run: ./teardown.sh
vordimous marked this conversation as resolved.
Show resolved Hide resolved

test-http-kafka-sync:
runs-on: ubuntu-latest
steps:
- name: Install apt packages
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: librdkafka-dev libyajl-dev
version: 1.0
- name: Install kcat
working-directory: /tmp
run: |
set -x
curl -L -o kcat https://github.com/attilakreiner/kcat/releases/download/1.7.1/kcat-linux-$(arch)
chmod +x kcat
sudo mv kcat /usr/local/bin
kcat 2>&1 | grep "Version 1.7.1"
Comment on lines +56 to +63
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use apt package kafkacat instead of this manual install?

https://github.com/edenhill/kcat?tab=readme-ov-file#install

Copy link
Contributor Author

@attilakreiner attilakreiner May 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The apt package kafkacat installs kafkacat version 1.6.0 that means it's lagging ca. one year behind the latest release. Even if we installed that we'd need to do some manual steps (e.g. renaming the executable from kafkacat to kcat) to keep the test in sync with the README and executable on other systems (e.g. on a Mac which has the latest kcat installed with brew).

Copy link
Contributor Author

@attilakreiner attilakreiner May 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I tested it, and that approach runs the test green, too. This is the alternative configuration:

      - name: Install apt packages
        uses: awalsh128/cache-apt-pkgs-action@latest
        with:
          packages: kafkacat
          version: 1.0
      - name: Setup kcat
        run: |
          sudo ln -s /usr/bin/kafkacat /usr/local/bin/kcat
          kcat 2>&1 | grep "Version 1.6.0"

Pls LMK which one you prefer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted the apt install commit as discussed, so going back to manual installation of kcat, as the decision was to install the latest version.

- name: Checkout
uses: actions/checkout@v3
- name: Create k8s Kind Cluster
uses: helm/kind-action@v1
- name: Setup
working-directory: http.kafka.sync
run: ./setup.sh
- name: Execute Test
working-directory: http.kafka.sync
run: |
set -o pipefail
./test.sh | tee $GITHUB_STEP_SUMMARY
- name: Teardown
if: always()
working-directory: http.kafka.sync
run: ./teardown.sh
69 changes: 69 additions & 0 deletions http.kafka.sync/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash

# GIVEN
ZILLA_PORT="7114"
KAFKA_PORT="9092"
ITEM_ID="5cf7a1d5-3772-49ef-86e7-ba6f2c7d7d07"
GREETING="Hello, World!"
GREETING_DATE="Hello, World! $(date)"
EXPECTED="{\"greeting\":\"$GREETING_DATE\"}"

echo \# Testing http.kafka.sync
echo ZILLA_PORT=$ZILLA_PORT
echo KAFKA_PORT=$KAFKA_PORT
echo ITEM_ID=$ITEM_ID
echo GREETING=$GREETING
echo GREETING_DATE=$GREETING_DATE
echo EXPECTED=$EXPECTED
echo

# WHEN
# send request to zilla
timeout 300 curl -vs \
-X "PUT" http://localhost:$ZILLA_PORT/items/$ITEM_ID \
-H "Idempotency-Key: 1" \
-H "Content-Type: application/json" \
-d "{\"greeting\":\"$GREETING\"}" | tee .testoutput &

# fetch correlation id from kafka with kcat; retry until ready
for i in $(seq 1 20); do
CORRELATION_ID=$(timeout 10 kcat -C -b localhost:$KAFKA_PORT -t items-requests -J -u | jq -r '.headers | index("zilla:correlation-id") as $index | .[$index + 1]')
if [[ ! -z "$CORRELATION_ID" ]]; then
break
fi
done
echo CORRELATION_ID=$CORRELATION_ID
if [[ -z "$CORRELATION_ID" ]]; then
echo ❌
exit 1
fi

# push response to kafka with kcat
echo "{\"greeting\":\"$GREETING_DATE\"}" | \
kcat -P \
-b localhost:$KAFKA_PORT \
-t items-responses \
-k "$ITEM_ID" \
-H ":status=200" \
-H "zilla:correlation-id=$CORRELATION_ID"

# fetch the output of zilla request; retry until ready
for i in $(seq 1 20); do
OUTPUT=$(cat .testoutput)
if [[ ! -z "$OUTPUT" ]]; then
break
fi
sleep 10
done
echo
echo OUTPUT=$OUTPUT


# THEN
rm .testoutput
if [[ "$OUTPUT" == "$EXPECTED" ]]; then
echo ✅
else
echo ❌
exit 1
fi
25 changes: 25 additions & 0 deletions tcp.echo/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
set -x
# GIVEN
PORT="12345"
INPUT="Hello, Zilla!"
EXPECTED="Hello, Zilla!"
echo \# Testing tcp.echo
echo PORT=$PORT
echo INPUT=$INPUT
echo EXPECTED=$EXPECTED
echo

# WHEN
OUTPUT=$(echo $INPUT | nc -w 1 localhost $PORT)
RESULT=$?
echo OUTPUT=$OUTPUT
echo RESULT=$RESULT

# THEN
if [[ $RESULT -eq 0 && "$OUTPUT" == "$EXPECTED" ]]; then
echo ✅
else
echo ❌
exit 1
fi
25 changes: 25 additions & 0 deletions tls.echo/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# GIVEN
PORT="23456"
INPUT="Hello, Zilla!"
EXPECTED="Hello, Zilla!"
echo \# Testing tls.echo
echo PORT=$PORT
echo INPUT=$INPUT
echo EXPECTED=$EXPECTED
echo

# WHEN
OUTPUT=$(echo $INPUT | timeout 2 openssl s_client -connect localhost:$PORT -CAfile test-ca.crt -quiet -alpn echo)
RESULT=$?
echo OUTPUT=$OUTPUT
echo RESULT=$RESULT

# THEN
if [[ $RESULT -eq 124 && "$OUTPUT" == "$EXPECTED" ]]; then
echo ✅
else
echo ❌
exit 1
fi
Loading