Skip to content

chore: automate checking that the quickstart works as expected #250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ REDIS_PORT="6379"
REDIS_PASSWORD="password"
REDIS_DATABASE="0"

# Clickhouse
CLICKHOUSE_ADDR="clickhouse:9000"
CLICKHOUSE_USERNAME="default"
CLICKHOUSE_DATABASE="outpost"
CLICKHOUSE_PASSWORD=""

# Misc Configs
PUBLISHMQ_MAX_CONCURRENCY=1
DELIVERYMQ_MAX_CONCURRENCY=1
Expand All @@ -46,6 +40,16 @@ TOPICS="user.created,user.updated,user.deleted" # comma separated list of topics

# DISABLE_TELEMETRY=true

# ============================== Log Storage ==============================

# Clickhouse
# CLICKHOUSE_ADDR="clickhouse:9000"
# CLICKHOUSE_USERNAME="default"
# CLICKHOUSE_DATABASE="outpost"
# CLICKHOUSE_PASSWORD=""

# POSTGRES_URL="postgres://outpost:outpost@postgres:5432/outpost?sslmode=disable"

# ============================== Infra MQ ==============================
# MQs, Uncomment the one you want to use

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@

# Misc
.DS_Store

# Scripted test runs
test/runs
1 change: 1 addition & 0 deletions test/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rm -rf runs/*
108 changes: 108 additions & 0 deletions test/quickstart.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/bin/bash

TEST_SCRIPT_DIR=$(dirname "$0")
TEST_RUN_ID=$(date +%Y-%m-%d_%H%M%S)
TEST_RUN_DIR="$TEST_SCRIPT_DIR/runs/$TEST_RUN_ID"
DOCKER_COMPOSE_DIR="$TEST_RUN_DIR/examples/docker-compose"
TEST_API_KEY="this_is_a_test_api_key"

echo "Creating a new test run $TEST_RUN_DIR"

mkdir "$TEST_RUN_DIR"

git clone https://github.com/hookdeck/outpost.git "$TEST_RUN_DIR"
cp .env.example "$TEST_RUN_DIR/examples/docker-compose/.env"

cd "$DOCKER_COMPOSE_DIR"

wait_for_service() {
local url=$1
local timeout=6
while ! curl --fail --silent "$url"; do
printf '.'
sleep 5
((timeout--))
if [ $timeout -le 0 ]; then
echo "Timeout reached. Exiting."
exit 1
fi
done
}

# Update the <API_KEY> value within the new .env file
sed -i '' "s/apikey/$TEST_API_KEY/" .env

docker-compose -f compose.yml -f compose-rabbitmq.yml -f compose-postgres.yml up -d

# Wait until the services are running
echo "Waiting for the services to start"
wait_for_service "localhost:3333/api/v1/healthz"

echo ""
echo "✅ Services are up and running"

echo ""
echo "Creating a tenant"

# Create a tenant
curl --location --request PUT "localhost:3333/api/v1/$TEST_RUN_ID" \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $TEST_API_KEY"

# Create a webhook destination
echo ""
echo "Creating a webhook destination"

curl --location "localhost:3333/api/v1/$TEST_RUN_ID/destinations" \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $TEST_API_KEY" \
--data "{
\"type\": \"webhook\",
\"topics\": [\"*\"],
\"config\": {
\"url\": \"http://host.docker.internal:4444/webhook/$TEST_RUN_ID\"
}
}"

# Start a simple HTTP server in the background
printf "\n\nStarting a simple HTTP server in the background"
touch "server.log"
python3 "../../../../server.py" 4444 > "server.log" 2>&1 &
printf "\nWaiting for the test server to start..."
wait_for_service "localhost:4444"
printf "\n✅ Test server started"

# Capture the server's PID to kill it later
SERVER_PID=$!
# Capture the killing of the script and kill the server
trap "kill $SERVER_PID; echo 'Script interrupted. Killing the server...'; exit 1" INT TERM

# Publish an event
printf "\n\nPublishing an event"

EVENT_BODY='{"user_id":"userid"}'

curl --location 'localhost:3333/api/v1/publish' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $TEST_API_KEY" \
--data "{
\"tenant_id\": \"$TEST_RUN_ID\",
\"topic\": \"user.created\",
\"eligible_for_retry\": true,
\"metadata\": {
\"meta\": \"data\"
},
\"data\": $EVENT_BODY
}"

# Example condition: wait for a specific log entry
printf "\nWaiting for the expected event to reach test server for test run $TEST_RUN_ID..."
while ! grep -q "$EVENT_BODY" "server.log"; do
printf '.'
sleep 5
done
echo ""
echo "✅ Received the expected request. Success! Exiting."

# Now kill the server
kill $SERVER_PID
38 changes: 38 additions & 0 deletions test/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import http.server
import logging
import sys


class SimpleHTTPRequestHandler(http.server.BaseHTTPRequestHandler):
def do_POST(self):
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
post_data = self.rfile.read()
logging.info(
"POST request,\nPath: %s\nHeaders:\n%s\n\nBody:\n%s\n",
str(self.path),
str(self.headers),
post_data.decode("utf-8"),
)
self.send_response(200)
self.end_headers()
self.wfile.write(b"POST request received")

def do_GET(self):
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
logging.info(
"GET request,\nPath: %s\nHeaders:\n%s\n",
str(self.path),
str(self.headers),
)
self.send_response(200)
self.end_headers()
self.wfile.write(b"GET request received")


if len(sys.argv) != 2:
print("Usage: python server.py <port>")
sys.exit(1)

port = int(sys.argv[1])
httpd = http.server.HTTPServer(("127.0.0.1", port), SimpleHTTPRequestHandler)
httpd.serve_forever()