summaryrefslogtreecommitdiff
path: root/tests/integration.sh
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2024-08-11 07:12:53 -0300
committerEuAndreh <eu@euandre.org>2024-08-11 07:12:53 -0300
commitdb44fd6aa6e0c3c9ab826e6f217cb555465c0fc4 (patch)
treec680e3b1874186c006fe08ddbceeed61cc7886ca /tests/integration.sh
parentInitial empty commit (diff)
downloaduntls-db44fd6aa6e0c3c9ab826e6f217cb555465c0fc4.tar.gz
untls-db44fd6aa6e0c3c9ab826e6f217cb555465c0fc4.tar.xz
Initial implementation: copy structure from "binder" project
Diffstat (limited to 'tests/integration.sh')
-rwxr-xr-xtests/integration.sh73
1 files changed, 73 insertions, 0 deletions
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