diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 00000000..c30d8a09 --- /dev/null +++ b/.github/workflows/test.yaml @@ -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 + + 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" + - 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 diff --git a/http.kafka.sync/test.sh b/http.kafka.sync/test.sh new file mode 100755 index 00000000..d3969b90 --- /dev/null +++ b/http.kafka.sync/test.sh @@ -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 diff --git a/tcp.echo/test.sh b/tcp.echo/test.sh new file mode 100755 index 00000000..7a3d0983 --- /dev/null +++ b/tcp.echo/test.sh @@ -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 diff --git a/tls.echo/test.sh b/tls.echo/test.sh new file mode 100755 index 00000000..18f4cc1d --- /dev/null +++ b/tls.echo/test.sh @@ -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