From db44fd6aa6e0c3c9ab826e6f217cb555465c0fc4 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Sun, 11 Aug 2024 07:12:53 -0300 Subject: Initial implementation: copy structure from "binder" project --- tests/integration.sh | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100755 tests/integration.sh (limited to 'tests/integration.sh') diff --git a/tests/integration.sh b/tests/integration.sh new file mode 100755 index 0000000..e0a92dc --- /dev/null +++ b/tests/integration.sh @@ -0,0 +1,73 @@ +#!/bin/sh +set -eu + +. tests/lib.sh + + +test_exits_when_upstream_errors() { + testing 'exits when upstream errors' + + N="$LINENO" + OUT="$(mkstemp)" + ERR="$(mkstemp)" + trap 'rm -f "$OUT" "$ERR" s1.socket client.txt' EXIT + + rm -f s1.socket + ./binder.bin localhost:1234 s1.socket 1>"$OUT" 2>"$ERR" & + pid=$! + while ! lsof -s TCP:LISTEN -i :1234 > /dev/null; do + true + done + + echo request | socat tcp-connect:localhost:1234 stdio > client.txt + kill $pid + wait + + assert_fgrep_stdout 'listen-start' + assert_fgrep_stdout 'active-connections' + assert_fgrep_stdout 'dial-connection' + assert_empty_stderr + assert_empty_stream 'client.txt' client.txt + rm -f "$OUT" "$ERR" s1.socket client.txt + + test_ok +} + +test_works_from_client_to_server() { + testing 'works from client to server' + + N="$LINENO" + OUT="$(mkstemp)" + ERR="$(mkstemp)" + trap 'rm -f "$OUT" "$ERR" s2.socket client.txt server.txt' EXIT + + rm -f s2.socket + ./binder.bin localhost:1234 s2.socket 1>"$OUT" 2>"$ERR" & + pid=$! + while ! lsof -s TCP:LISTEN -i :1234 > /dev/null; do + true + done + + echo response | socat unix-listen:s2.socket stdio > server.txt & + while [ ! -S s2.socket ]; do + true + done + + echo request | socat tcp-connect:localhost:1234 stdio > client.txt + kill $pid + wait + + assert_fgrep_stdout 'listen-start' + assert_fgrep_stdout 'active-connections' + assert_empty_stderr + assert_fgrep_stream 'client.txt' client.txt 'response' + assert_fgrep_stream 'server.txt' server.txt 'request' + rm -f "$OUT" "$ERR" s2.socket client.txt server.txt + + test_ok +} + + +exit # FIXME +test_exits_when_upstream_errors +test_works_from_client_to_server -- cgit v1.2.3