From 64a032189b6076a3d2e316f8e5216ff04eebdcee Mon Sep 17 00:00:00 2001 From: AJ Date: Fri, 8 Nov 2024 13:02:54 -0500 Subject: [PATCH] add grpc echo tests --- grpc.echo/README.md | 6 ++-- grpc.echo/test.sh | 60 ++++++++++++++++++++++++++++++++++ grpc.kafka.echo/README.md | 7 ++-- grpc.kafka.echo/compose.yaml | 3 +- grpc.kafka.echo/test.sh | 62 ++++++++++++++++++++++++++++++++++++ grpc.kafka.fanout/README.md | 5 +-- grpc.kafka.proxy/README.md | 7 ++-- grpc.proxy/README.md | 2 +- 8 files changed, 138 insertions(+), 14 deletions(-) create mode 100755 grpc.echo/test.sh create mode 100755 grpc.kafka.echo/test.sh diff --git a/grpc.echo/README.md b/grpc.echo/README.md index 550012e3..3334a64e 100644 --- a/grpc.echo/README.md +++ b/grpc.echo/README.md @@ -4,8 +4,8 @@ Listens on tcp port `7151` and will echo grpc message sent by client. ## Requirements -- jq, nc, grpcurl - Compose compatible host +- [grpcurl](https://github.com/fullstorydev/grpcurl) - [ghz](https://ghz.sh/docs/install) ## Setup @@ -29,7 +29,7 @@ docker compose up -d Echo `{"message":"Hello World"}` message via unary rpc using `grpcurl` command. ```bash -grpcurl -insecure -proto echo.proto -d '{"message":"Hello World"}' localhost:7151 example.EchoService.EchoUnary +grpcurl -plaintext -proto echo.proto -d '{"message":"Hello World"}' localhost:7151 example.EchoService.EchoUnary ``` output: @@ -45,7 +45,7 @@ output: Echo messages via bidirectional streaming rpc. ```bash -grpcurl -insecure -proto echo.proto -d @ localhost:7151 example.EchoService.EchoBidiStream +grpcurl -plaintext -proto echo.proto -d @ localhost:7151 example.EchoService.EchoBidiStream ``` Paste below message. diff --git a/grpc.echo/test.sh b/grpc.echo/test.sh new file mode 100755 index 00000000..d560aef9 --- /dev/null +++ b/grpc.echo/test.sh @@ -0,0 +1,60 @@ +#!/bin/sh +set -x + +EXIT=0 + +# GIVEN +PORT="7151" +INPUT='{"message":"Hello World"}' +EXPECTED='{ + "message": "Hello World" +}' +echo \# Testing grpc.echo/example.EchoService.EchoUnary +echo PORT="$PORT" +echo INPUT="$INPUT" +echo EXPECTED="$EXPECTED" +echo + +# WHEN +OUTPUT=$(docker run --rm -v ./echo.proto:/echo.proto fullstorydev/grpcurl -plaintext -proto echo.proto -d "$INPUT" host.docker.internal:$PORT example.EchoService.EchoUnary) +RESULT=$? +echo RESULT="$RESULT" +# THEN +echo OUTPUT="$OUTPUT" +echo EXPECTED="$EXPECTED" +echo +if [ "$RESULT" -eq 0 ] && [ "$OUTPUT" = "$EXPECTED" ]; then + echo ✅ +else + echo ❌ + EXIT=1 +fi + +# GIVEN +PORT="7151" +INPUT='{"message":"Hello World"}' +EXPECTED='{ + "message": "Hello World" +}' +echo \# Testing grpc.echo/example.EchoService.EchoBidiStream +echo PORT="$PORT" +echo INPUT="$INPUT" +echo EXPECTED="$EXPECTED" +echo + +# WHEN +OUTPUT=$(docker run --rm -v ./echo.proto:/echo.proto fullstorydev/grpcurl -plaintext -proto echo.proto -d "$INPUT" host.docker.internal:$PORT example.EchoService.EchoBidiStream) +RESULT=$? +echo RESULT="$RESULT" +# THEN +echo OUTPUT="$OUTPUT" +echo EXPECTED="$EXPECTED" +echo +if [ "$RESULT" -eq 0 ] && [ "$OUTPUT" = "$EXPECTED" ]; then + echo ✅ +else + echo ❌ + EXIT=1 +fi + +exit $EXIT diff --git a/grpc.kafka.echo/README.md b/grpc.kafka.echo/README.md index bf3f2862..54971b2d 100644 --- a/grpc.kafka.echo/README.md +++ b/grpc.kafka.echo/README.md @@ -4,8 +4,9 @@ Listens on https port `7151` and will exchange grpc message in protobuf format t ## Requirements -- jq, nc, grpcurl +- jq - Compose compatible host +- [grpcurl](https://github.com/fullstorydev/grpcurl) - [ghz](https://ghz.sh/docs/install) ## Setup @@ -29,7 +30,7 @@ docker compose up -d Echo `{"message":"Hello World"}` message via unary rpc using `grpcurl` client. ```bash -grpcurl -insecure -proto echo.proto -d '{"message":"Hello World"}' localhost:7151 grpc.examples.echo.Echo.UnaryEcho +grpcurl -plaintext -proto echo.proto -d '{"message":"Hello World"}' localhost:7151 grpc.examples.echo.Echo.UnaryEcho ``` output: @@ -98,7 +99,7 @@ output: Echo messages via bidirectional streaming rpc. ```bash -grpcurl -insecure -proto echo.proto -d @ localhost:7151 grpc.examples.echo.Echo.BidirectionalStreamingEcho +grpcurl -plaintext -proto echo.proto -d @ localhost:7151 grpc.examples.echo.Echo.BidirectionalStreamingEcho ``` Paste below message. diff --git a/grpc.kafka.echo/compose.yaml b/grpc.kafka.echo/compose.yaml index d333ca8c..ae7179df 100644 --- a/grpc.kafka.echo/compose.yaml +++ b/grpc.kafka.echo/compose.yaml @@ -57,8 +57,7 @@ services: command: - | echo -e "Creating kafka topic"; - /opt/bitnami/kafka/bin/kafka-topics.sh --bootstrap-server kafka:29092 --create --if-not-exists --topic items-requests - /opt/bitnami/kafka/bin/kafka-topics.sh --bootstrap-server kafka:29092 --create --if-not-exists --topic items-responses --config cleanup.policy=compact + /opt/bitnami/kafka/bin/kafka-topics.sh --bootstrap-server kafka:29092 --create --if-not-exists --topic echo-messages echo -e "Successfully created the following topics:"; /opt/bitnami/kafka/bin/kafka-topics.sh --bootstrap-server kafka:29092 --list; diff --git a/grpc.kafka.echo/test.sh b/grpc.kafka.echo/test.sh new file mode 100755 index 00000000..ea442e4e --- /dev/null +++ b/grpc.kafka.echo/test.sh @@ -0,0 +1,62 @@ +#!/bin/sh +set -x + +EXIT=0 + +# GIVEN +PORT="7151" +INPUT='{"message":"Hello World"}' +EXPECTED='{ + "message": "Hello World" +}' +echo \# Testing grpc.kafka.echo/UnaryEcho +echo PORT="$PORT" +echo INPUT="$INPUT" +echo EXPECTED="$EXPECTED" +echo + +# WHEN +OUTPUT=$(docker run --rm -v ./echo.proto:/echo.proto fullstorydev/grpcurl -plaintext -proto echo.proto -d "$INPUT" host.docker.internal:$PORT grpc.examples.echo.Echo.UnaryEcho) +RESULT=$? +echo RESULT="$RESULT" + +# THEN +echo OUTPUT="$OUTPUT" +echo EXPECTED="$EXPECTED" +echo +if [ "$RESULT" -eq 0 ] && [ "$OUTPUT" = "$EXPECTED" ]; then + echo ✅ +else + echo ❌ + EXIT=1 +fi + +# GIVEN +PORT="7151" +INPUT='{"message":"Hello World"}' +EXPECTED='{ + "message": "Hello World" +}' +echo \# Testing grpc.kafka.echo/BidirectionalStreamingEcho +echo PORT="$PORT" +echo INPUT="$INPUT" +echo EXPECTED="$EXPECTED" +echo + +# WHEN +OUTPUT=$(docker run --rm -v ./echo.proto:/echo.proto fullstorydev/grpcurl -plaintext -proto echo.proto -d "$INPUT" host.docker.internal:$PORT grpc.examples.echo.Echo.BidirectionalStreamingEcho) +RESULT=$? +echo RESULT="$RESULT" + +# THEN +echo OUTPUT="$OUTPUT" +echo EXPECTED="$EXPECTED" +echo +if [ "$RESULT" -eq 0 ] && [ "$OUTPUT" = "$EXPECTED" ]; then + echo ✅ +else + echo ❌ + EXIT=1 +fi + +exit $EXIT diff --git a/grpc.kafka.fanout/README.md b/grpc.kafka.fanout/README.md index 2f19fd8a..58445a0a 100644 --- a/grpc.kafka.fanout/README.md +++ b/grpc.kafka.fanout/README.md @@ -4,8 +4,9 @@ Listens on https port `7151` and fanout messages from `messages` topic in Kafka. ## Requirements -- jq, nc, grpcurl, protoc +- jq, protoc - Compose compatible host +- [grpcurl](https://github.com/fullstorydev/grpcurl) ## Setup @@ -41,7 +42,7 @@ docker compose -p zilla-grpc-kafka-fanout exec kafkacat \ Stream messages via server streaming rpc. ```bash -grpcurl -insecure -proto fanout.proto -d '' localhost:7151 example.FanoutService.FanoutServerStream +grpcurl -plaintext -proto fanout.proto -d '' localhost:7151 example.FanoutService.FanoutServerStream ``` output: diff --git a/grpc.kafka.proxy/README.md b/grpc.kafka.proxy/README.md index 7145d7a5..e4433806 100644 --- a/grpc.kafka.proxy/README.md +++ b/grpc.kafka.proxy/README.md @@ -4,8 +4,9 @@ Listens on https port `7151` and uses kafka as proxy to talk to `grpc-echo` on t ## Requirements -- jq, nc, grpcurl +- jq - Compose compatible host +- [grpcurl](https://github.com/fullstorydev/grpcurl) ## Setup @@ -28,7 +29,7 @@ docker compose up -d Echo `{"message":"Hello World"}` message via unary rpc. ```bash -grpcurl -insecure -proto echo.proto -d '{"message":"Hello World"}' localhost:7151 grpc.examples.echo.Echo.UnaryEcho +grpcurl -plaintext -proto echo.proto -d '{"message":"Hello World"}' localhost:7151 grpc.examples.echo.Echo.UnaryEcho ``` output: @@ -97,7 +98,7 @@ output: Echo messages via bidirectional streaming rpc. ```bash -grpcurl -insecure -proto echo.proto -d @ localhost:7151 grpc.examples.echo.Echo.BidirectionalStreamingEcho <