~fnux/matrix-yggdrasil-http-proxy

1b4d8462372d84a210c4b4b25883e67e007198e3 — Timothée Floure 4 years ago 239aa89
Add basic structure for integration tests
2 files changed, 51 insertions(+), 0 deletions(-)

M .build.yml
A run-integration-tests.sh
M .build.yml => .build.yml +3 -0
@@ 13,3 13,6 @@ tasks:
  - build: |
      cd matrix-yggdrasil-http-proxy
      go build
  - test: |
      cd matrix-yggdrasil-http-proxy
      ./run-integration-tests.sh

A run-integration-tests.sh => run-integration-tests.sh +48 -0
@@ 0,0 1,48 @@
#!/bin/sh

set -e
set -x

BIN="matrix-yggdrasil-http-proxy"
TMPDIR=$(mktemp -d)

NODE_A_CONF="$TMPDIR/node-A.conf"
NODE_A_PROXY_PORT=8080
NODE_A_TARGET="http://127.0.0.1:9090"

NODE_B_CONF="$TMPDIR/node-B.conf"
NODE_B_PROXY_PORT=8081
NODE_B_TARGET="http://127.0.0.1:9091"

if [ ! -x "$BIN" ]; then
	echo "Cannot execute $BIN." >&2
fi

# Generate Yggdrasil configurations.
./$BIN -gen-conf > "$NODE_A_CONF"
sed -i -e "s/  Peers: \[\]/  Peers: \[ \'tcp:\/\/127.0.0.1:54321\' \]/" "$NODE_A_CONF"
./$BIN -gen-conf > "$NODE_B_CONF"
sed -i -e "s/  Peers: \[\]/  Peers: \[ \'tcp:\/\/127.0.0.1:54321\' \]/" "$NODE_B_CONF"

# Kill childs when script exit.
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT

# Extract node IDs:
node_a_id=$(./$BIN -use-conf-file "$NODE_A_CONF" -get-node-id | tail -n 1)
node_b_id=$(./$BIN -use-conf-file "$NODE_B_CONF" -get-node-id | tail -n 1)

# Launch both nodes.
./$BIN -use-conf-file "$NODE_A_CONF" \
	-http-port $NODE_A_PROXY_PORT &
	-http-target $NODE_A_TARGET &
./$BIN -use-conf-file "$NODE_B_CONF" \
	-http-port $NODE_B_PROXY_PORT \
	-http-target $NODE_B_TARGET &

# Wait for nodes to be properly connected.
sleep 1

# TODO: Run integration tests :-)
nc -l 9091 &
curl "http://127.0.0.1:$NODE_A_PROXY_PORT/" -H "x-yggdrasil-target: $node_b_id" &
sleep 1