forked from torrust/torrust-index
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: [torrust#223] run E2E with MySQL too
E2E tests are only executed with SQLite.
- Loading branch information
1 parent
5465e0c
commit c6346a5
Showing
11 changed files
with
227 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
log_level = "info" | ||
|
||
[website] | ||
name = "Torrust" | ||
|
||
[tracker] | ||
url = "udp://tracker:6969" | ||
mode = "Public" | ||
api_url = "http://tracker:1212" | ||
token = "MyAccessToken" | ||
token_valid_seconds = 7257600 | ||
|
||
[net] | ||
port = 3001 | ||
|
||
[auth] | ||
email_on_signup = "Optional" | ||
min_password_length = 6 | ||
max_password_length = 64 | ||
secret_key = "MaxVerstappenWC2021" | ||
|
||
[database] | ||
connect_url = "mysql://root:root_secret_password@mysql:3306/torrust_index_backend_e2e_testing" | ||
|
||
[mail] | ||
email_verification_enabled = false | ||
from = "[email protected]" | ||
reply_to = "[email protected]" | ||
username = "" | ||
password = "" | ||
server = "mailcatcher" | ||
port = 1025 | ||
|
||
[image_cache] | ||
max_request_timeout_ms = 1000 | ||
capacity = 128000000 | ||
entry_size_limit = 4000000 | ||
user_quota_period_seconds = 3600 | ||
user_quota_bytes = 64000000 | ||
|
||
[api] | ||
default_torrent_page_size = 10 | ||
max_torrent_page_size = 30 | ||
|
||
[tracker_statistics_importer] | ||
torrent_info_update_interval = 3600 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
docker compose down |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/bin/bash | ||
|
||
./docker/bin/e2e/mysql/e2e-env-down.sh | ||
|
||
# Delete the databases and recreate them. | ||
|
||
# Index Backend | ||
|
||
# Database credentials | ||
MYSQL_USER="root" | ||
MYSQL_PASSWORD="root_secret_password" | ||
MYSQL_HOST="localhost" | ||
MYSQL_DATABASE="torrust_index_backend_e2e_testing" | ||
|
||
# Create the MySQL database for the index backend. Assumes MySQL client is installed. | ||
echo "Creating MySQL database $MYSQL_DATABASE for E2E testing ..." | ||
mysql -h $MYSQL_HOST -u $MYSQL_USER -p$MYSQL_PASSWORD -e "DROP DATABASE IF EXISTS $MYSQL_DATABASE; CREATE DATABASE $MYSQL_DATABASE;" | ||
|
||
# Tracker | ||
|
||
# Delete tracker database | ||
rm -f ./storage/database/torrust_tracker_e2e_testing.db | ||
|
||
# Generate storage directory if it does not exist | ||
mkdir -p "./storage/database" | ||
|
||
# Generate the sqlite database for the tracker if it does not exist | ||
if ! [ -f "./storage/database/torrust_tracker_e2e_testing.db" ]; then | ||
touch ./storage/database/torrust_tracker_e2e_testing.db | ||
echo ";" | sqlite3 ./storage/database/torrust_tracker_e2e_testing.db | ||
fi | ||
|
||
./docker/bin/e2e/mysql/e2e-env-up.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
|
||
./docker/bin/e2e/mysql/e2e-env-down.sh | ||
./docker/bin/e2e/mysql/e2e-env-up.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
|
||
TORRUST_IDX_BACK_USER_UID=${TORRUST_IDX_BACK_USER_UID:-1000} \ | ||
docker compose build | ||
|
||
TORRUST_IDX_BACK_USER_UID=${TORRUST_IDX_BACK_USER_UID:-1000} \ | ||
TORRUST_IDX_BACK_CONFIG=$(cat config-idx-back.mysql.local.toml) \ | ||
TORRUST_IDX_BACK_MYSQL_DATABASE="torrust_index_backend_e2e_testing" \ | ||
TORRUST_TRACKER_CONFIG=$(cat config-tracker.local.toml) \ | ||
TORRUST_TRACKER_API_TOKEN=${TORRUST_TRACKER_API_TOKEN:-MyAccessToken} \ | ||
docker compose up -d | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/bin/bash | ||
|
||
CURRENT_USER_NAME=$(whoami) | ||
CURRENT_USER_ID=$(id -u) | ||
echo "User name: $CURRENT_USER_NAME" | ||
echo "User id: $CURRENT_USER_ID" | ||
|
||
TORRUST_IDX_BACK_USER_UID=$CURRENT_USER_ID | ||
TORRUST_TRACKER_USER_UID=$CURRENT_USER_ID | ||
export TORRUST_IDX_BACK_USER_UID | ||
export TORRUST_TRACKER_USER_UID | ||
|
||
wait_for_container_to_be_healthy() { | ||
local container_name="$1" | ||
local max_retries="$2" | ||
local retry_interval="$3" | ||
local retry_count=0 | ||
|
||
while [ $retry_count -lt "$max_retries" ]; do | ||
container_health="$(docker inspect --format='{{json .State.Health}}' "$container_name")" | ||
if [ "$container_health" != "{}" ]; then | ||
container_status="$(echo "$container_health" | jq -r '.Status')" | ||
if [ "$container_status" == "healthy" ]; then | ||
echo "Container $container_name is healthy" | ||
return 0 | ||
fi | ||
fi | ||
|
||
retry_count=$((retry_count + 1)) | ||
echo "Waiting for container $container_name to become healthy (attempt $retry_count of $max_retries)..." | ||
sleep "$retry_interval" | ||
done | ||
|
||
echo "Timeout reached, container $container_name is not healthy" | ||
return 1 | ||
} | ||
|
||
# Install tool to create torrent files | ||
cargo install imdl || exit 1 | ||
|
||
cp .env.local .env || exit 1 | ||
./bin/install.sh || exit 1 | ||
|
||
# Start E2E testing environment | ||
./docker/bin/e2e/mysql/e2e-env-up.sh || exit 1 | ||
|
||
wait_for_container_to_be_healthy torrust-mysql-1 10 3 | ||
# todo: implement healthchecks for tracker and backend and wait until they are healthy | ||
#wait_for_container torrust-tracker-1 10 3 | ||
#wait_for_container torrust-idx-back-1 10 3 | ||
sleep 20s | ||
|
||
# Just to make sure that everything is up and running | ||
docker ps | ||
|
||
# Database credentials | ||
MYSQL_USER="root" | ||
MYSQL_PASSWORD="root_secret_password" | ||
MYSQL_HOST="localhost" | ||
MYSQL_DATABASE="torrust_index_backend_e2e_testing" | ||
|
||
# Create the MySQL database for the index backend. Assumes MySQL client is installed. | ||
echo "Creating MySQL database $MYSQL_DATABASE for for E2E testing ..." | ||
mysql -h $MYSQL_HOST -u $MYSQL_USER -p$MYSQL_PASSWORD -e "CREATE DATABASE IF NOT EXISTS $MYSQL_DATABASE;" | ||
|
||
# Run E2E tests with shared app instance | ||
TORRUST_IDX_BACK_E2E_SHARED=true TORRUST_IDX_BACK_E2E_CONFIG_PATH="./config-idx-back.mysql.local.toml" cargo test || exit 1 | ||
|
||
# Stop E2E testing environment | ||
./docker/bin/e2e/mysql/e2e-env-down.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters