Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vordimous committed Nov 8, 2024
1 parent 64a0321 commit 950d29e
Show file tree
Hide file tree
Showing 9 changed files with 319 additions and 28 deletions.
12 changes: 9 additions & 3 deletions grpc.kafka.fanout/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,20 @@ docker compose up -d
Prepare protobuf message to send to Kafka topic.

```bash
echo 'message: "test"' | protoc --encode=example.FanoutMessage proto/fanout.proto > binary.data
echo 'message: "test"' | protoc --encode=example.FanoutMessage fanout.proto > binary.data
```

Copy the binary file into the `kafkacat` service.

```bash
docker compose -p zilla-grpc-kafka-fanout cp binary.data kafkacat:/tmp/binary.data
```

Produce protobuf message to Kafka topic, repeat to produce multiple messages.

```bash
docker compose -p zilla-grpc-kafka-fanout exec kafkacat \
kafkacat -P -b kafka:29092 -t messages -k -e ./binary.data
kafkacat -P -b kafka:29092 -t messages -k -e /tmp/binary.data
```

Stream messages via server streaming rpc.
Expand Down Expand Up @@ -95,7 +101,7 @@ Then produce another protobuf message to Kafka, repeat to produce multiple messa

```bash
docker compose -p zilla-grpc-kafka-fanout exec kafkacat \
kafkacat -P -b kafka:29092 -t messages -k -e ./binary.data
kafkacat -P -b kafka:29092 -t messages -k -e /tmp/binary.data
```

The reliable streaming client will recover and zilla deliver only the new message.
Expand Down
3 changes: 1 addition & 2 deletions grpc.kafka.fanout/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 messages
echo -e "Successfully created the following topics:";
/opt/bitnami/kafka/bin/kafka-topics.sh --bootstrap-server kafka:29092 --list;
Expand Down
4 changes: 2 additions & 2 deletions grpc.kafka.proxy/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ 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-requests
/opt/bitnami/kafka/bin/kafka-topics.sh --bootstrap-server kafka:29092 --create --if-not-exists --topic echo-responses
echo -e "Successfully created the following topics:";
/opt/bitnami/kafka/bin/kafka-topics.sh --bootstrap-server kafka:29092 --list;
Expand Down
115 changes: 115 additions & 0 deletions grpc.kafka.proxy/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#!/bin/sh
set -x

EXIT=0

# GIVEN
PORT="7151"
INPUT='{"message":"Hello World"}'
EXPECTED='{
"message": "Hello World"
}'
echo \# Testing grpc.kafka.proxy/grpc.examples.echo.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"
}
{
"message": "Hello World"
}
{
"message": "Hello World"
}
{
"message": "Hello World"
}
{
"message": "Hello World"
}
{
"message": "Hello World"
}
{
"message": "Hello World"
}
{
"message": "Hello World"
}
{
"message": "Hello World"
}
{
"message": "Hello World"
}'
echo \# Testing grpc.kafka.proxy/grpc.examples.echo.Echo.ServerStreamingEcho
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.ServerStreamingEcho)
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.proxy/grpc.examples.echo.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
4 changes: 2 additions & 2 deletions grpc.proxy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,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 -insecure -proto echo.proto -d '{"message":"Hello World"}' localhost:7153 grpc.examples.echo.Echo.UnaryEcho
```

output:
Expand All @@ -44,7 +44,7 @@ output:
Echo messages via bidirectional streaming rpc.

```bash
grpcurl -insecure -proto echo.proto -d @ localhost:7151 grpc.examples.echo.Echo.BidirectionalStreamingEcho
grpcurl -insecure -proto echo.proto -d @ localhost:7153 grpc.examples.echo.Echo.BidirectionalStreamingEcho
```

Paste below message.
Expand Down
91 changes: 91 additions & 0 deletions grpc.proxy/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/bin/sh
set -x

EXIT=0

# GIVEN
PORT="7153"
INPUT='{"message":"Hello World"}'
EXPECTED='{
"message": "Hello World"
}'
echo \# Testing grpc.kafka.proxy/grpc.examples.echo.Echo.UnaryEcho
echo PORT="$PORT"
echo INPUT="$INPUT"
echo EXPECTED="$EXPECTED"
echo

# WHEN
OUTPUT=$(docker run --rm -v ./echo.proto:/echo.proto fullstorydev/grpcurl -insecure -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="7153"
INPUT='{"message":"Hello World"}'
EXPECTED='{
"message": "Hello World"
}
{
"message": "Hello World"
}
{
"message": "Hello World"
}
{
"message": "Hello World"
}
{
"message": "Hello World"
}
{
"message": "Hello World"
}
{
"message": "Hello World"
}
{
"message": "Hello World"
}
{
"message": "Hello World"
}
{
"message": "Hello World"
}'
echo \# Testing grpc.kafka.proxy/grpc.examples.echo.Echo.ServerStreamingEcho
echo PORT="$PORT"
echo INPUT="$INPUT"
echo EXPECTED="$EXPECTED"
echo

# WHEN
OUTPUT=$(docker run --rm -v ./echo.proto:/echo.proto fullstorydev/grpcurl -insecure -proto echo.proto -d "$INPUT" host.docker.internal:$PORT grpc.examples.echo.Echo.ServerStreamingEcho)
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

# TODO remove once fixed
echo '❌ Tested on main. and does not work with described instructions'
EXIT=1

exit $EXIT
19 changes: 0 additions & 19 deletions http.filesystem/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ Listens on http port `7114` and serves files from the Zilla container's `/var/ww

## Requirements

- jq, nc
- Compose compatible host
- curl

## Setup

Expand Down Expand Up @@ -41,23 +39,6 @@ output:
</html>
```

```bash
curl --cacert test-ca.crt http://localhost:7114/index.html
```

output:

```html
<html>
<head>
<title>Welcome to Zilla!</title>
</head>
<body>
<h1>Welcome to Zilla!</h1>
</body>
</html>
```

## Teardown

The `teardown.sh` script will remove any resources created.
Expand Down
37 changes: 37 additions & 0 deletions http.filesystem/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh
set -x

EXIT=0

# GIVEN
PORT="7114"
EXPECTED='<html>
<head>
<title>Welcome to Zilla!</title>
</head>
<body>
<h1>Welcome to Zilla!</h1>
</body>
</html>'
echo \# Testing http.filesystem/
echo PORT="$PORT"
echo EXPECTED="$EXPECTED"
echo

# WHEN
OUTPUT=$(curl http://localhost:$PORT/index.html)
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
Loading

0 comments on commit 950d29e

Please sign in to comment.