|
| 1 | +#!/bin/bash |
| 2 | +# End-to-end self-test: drives a real TestingBot browser session through the |
| 3 | +# tunnel to a web server that only exists on this agent, proving the full |
| 4 | +# tunnel + status-update + annotation flow. |
| 5 | +set -euo pipefail |
| 6 | + |
| 7 | +workdir="$(mktemp -d)" |
| 8 | +cat >"${workdir}/index.html" <<'HTML' |
| 9 | +<!DOCTYPE html> |
| 10 | +<html><head><title>Buildkite E2E OK</title></head> |
| 11 | +<body><h1>Served from the Buildkite agent, reached through the TestingBot tunnel</h1></body></html> |
| 12 | +HTML |
| 13 | +(cd "${workdir}" && exec python3 -m http.server 8123) >/dev/null 2>&1 & |
| 14 | +server_pid=$! |
| 15 | +trap 'kill "${server_pid}" 2>/dev/null || true; rm -rf "${workdir}"' EXIT |
| 16 | + |
| 17 | +payload="$(jq -n \ |
| 18 | + --arg key "${TESTINGBOT_KEY}" \ |
| 19 | + --arg secret "${TESTINGBOT_SECRET}" \ |
| 20 | + --arg build "${TESTINGBOT_BUILD}" \ |
| 21 | + '{capabilities: {alwaysMatch: {browserName: "chrome", |
| 22 | + "tb:options": {key: $key, secret: $secret, build: $build, name: "plugin e2e — tunnel to localhost"}}}}')" |
| 23 | + |
| 24 | +echo "--- Creating TestingBot browser session" |
| 25 | +resp="$(curl -fsS -X POST "https://hub.testingbot.com/wd/hub/session" \ |
| 26 | + -H "Content-Type: application/json" -d "${payload}")" |
| 27 | +sid="$(echo "${resp}" | jq -r '.value.sessionId')" |
| 28 | +echo "session: ${sid}" |
| 29 | +echo "${sid}" >>"${TESTINGBOT_SESSIONS_FILE}" |
| 30 | + |
| 31 | +echo "--- Navigating remote browser to http://localhost:8123 (through the tunnel)" |
| 32 | +curl -fsS -X POST "https://hub.testingbot.com/wd/hub/session/${sid}/url" \ |
| 33 | + -H "Content-Type: application/json" -d '{"url": "http://localhost:8123/"}' >/dev/null |
| 34 | +sleep 2 |
| 35 | +title="$(curl -fsS "https://hub.testingbot.com/wd/hub/session/${sid}/title" | jq -r '.value')" |
| 36 | +echo "page title seen by remote browser: ${title}" |
| 37 | + |
| 38 | +curl -fsS -X DELETE "https://hub.testingbot.com/wd/hub/session/${sid}" >/dev/null |
| 39 | + |
| 40 | +[[ "${title}" == "Buildkite E2E OK" ]] |
0 commit comments