From c6c1b91f2653ece156ae4da8ca94143e58563a02 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Thu, 18 Apr 2024 14:03:14 +0200 Subject: [PATCH] WIP --- .github/workflows/test.yaml | 41 +++++++++++++++++++++++++++++++++++++ tcp.echo/test.sh | 25 ++++++++++++++++++++++ tls.echo/test.sh | 25 ++++++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 .github/workflows/test.yaml create mode 100755 tcp.echo/test.sh create mode 100755 tls.echo/test.sh diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 00000000..54203b69 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,41 @@ +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: Execute Test + run: | + cd tcp.echo + ./setup.sh + ./test.sh | tee -a $GITHUB_STEP_SUMMARY + - name: Teardown + if: always() + run: | + cd tcp.echo + ./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: Execute Test + run: | + cd tls.echo + ./setup.sh + ./test.sh | tee -a $GITHUB_STEP_SUMMARY + - name: Teardown + if: always() + run: | + cd tls.echo + ./teardown.sh diff --git a/tcp.echo/test.sh b/tcp.echo/test.sh new file mode 100755 index 00000000..3bc52ada --- /dev/null +++ b/tcp.echo/test.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -x +# GIVEN +PORT="12345" +INPUT="ZZZ 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..bff4d420 --- /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