Skip to content

Commit

Permalink
Merge #398: Use a different DB for E2E testing
Browse files Browse the repository at this point in the history
052e855 fix: [#392] use a different DB for E2E testing (Jose Celano)

Pull request description:

  To avoid accidentally overwriting the default database.

ACKs for top commit:
  josecelano:
    ACK 052e855

Tree-SHA512: a8467a3a6a6a4f5d5874a6a10bb29384ab860cdb73c9f22c75f2e8db32b1c6855b346cba54c37dbd3f4c15898e15a463ed2e058e957f5c8acea33208b5586c10
  • Loading branch information
josecelano committed Nov 22, 2023
2 parents fa3bba7 + 052e855 commit c17ebbd
Show file tree
Hide file tree
Showing 19 changed files with 198 additions and 103 deletions.
2 changes: 2 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ services:
environment:
- USER_ID=${USER_ID}
- TORRUST_INDEX_CONFIG=${TORRUST_INDEX_CONFIG}
- TORRUST_INDEX_DATABASE=${TORRUST_INDEX_DATABASE:-e2e_testing_sqlite3}
- TORRUST_INDEX_DATABASE_DRIVER=${TORRUST_INDEX_DATABASE_DRIVER:-sqlite3}
- TORRUST_INDEX_TRACKER_API_TOKEN=${TORRUST_INDEX_TRACKER_API_TOKEN:-MyAccessToken}
networks:
Expand All @@ -31,6 +32,7 @@ services:
environment:
- USER_ID=${USER_ID}
- TORRUST_TRACKER_CONFIG=${TORRUST_TRACKER_CONFIG}
- TORRUST_TRACKER_DATABASE=${TORRUST_TRACKER_DATABASE:-e2e_testing_sqlite3}
- TORRUST_TRACKER_DATABASE_DRIVER=${TORRUST_TRACKER_DATABASE_DRIVER:-sqlite3}
- TORRUST_TRACKER_API_ADMIN_TOKEN=${TORRUST_TRACKER_API_ADMIN_TOKEN:-MyAccessToken}
networks:
Expand Down
5 changes: 2 additions & 3 deletions contrib/dev-tools/container/e2e/mysql/e2e-env-down.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/bin/bash

TORRUST_INDEX_CONFIG=$(cat ./share/default/config/index.container.mysql.toml) \
TORRUST_TRACKER_CONFIG=$(cat ./share/default/config/tracker.container.mysql.toml) \
TORRUST_INDEX_CONFIG=$(cat ./share/default/config/index.e2e.container.mysql.toml) \
TORRUST_TRACKER_CONFIG=$(cat ./share/default/config/tracker.e2e.container.sqlite.toml) \
docker compose down

32 changes: 0 additions & 32 deletions contrib/dev-tools/container/e2e/mysql/e2e-env-reset.sh

This file was deleted.

4 changes: 0 additions & 4 deletions contrib/dev-tools/container/e2e/mysql/e2e-env-restart.sh

This file was deleted.

11 changes: 6 additions & 5 deletions contrib/dev-tools/container/e2e/mysql/e2e-env-up.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#!/bin/bash

TORRUST_INDEX_CONFIG=$(cat ./share/default/config/index.container.mysql.toml) \
TORRUST_INDEX_CONFIG=$(cat ./share/default/config/index.e2e.container.mysql.toml) \
docker compose build

USER_ID=${USER_ID:-1000} \
TORRUST_INDEX_CONFIG=$(cat ./share/default/config/index.container.mysql.toml) \
TORRUST_INDEX_CONFIG=$(cat ./share/default/config/index.e2e.container.mysql.toml) \
TORRUST_INDEX_DATABASE="torrust_index_e2e_testing" \
TORRUST_INDEX_DATABASE_DRIVER="mysql" \
TORRUST_INDEX_TRACKER_API_TOKEN="MyAccessToken" \
TORRUST_INDEX_MYSQL_DATABASE="torrust_index_e2e_testing" \
TORRUST_TRACKER_CONFIG=$(cat ./share/default/config/tracker.container.sqlite3.toml) \
TORRUST_TRACKER_CONFIG=$(cat ./share/default/config/tracker.e2e.container.sqlite3.toml) \
TORRUST_TRACKER_DATABASE="e2e_testing_sqlite3" \
TORRUST_TRACKER_DATABASE_DRIVER="sqlite3" \
TORRUST_TRACKER_API_ADMIN_TOKEN="MyAccessToken" \
docker compose up -d

docker compose up --detach --pull always --remove-orphans
16 changes: 14 additions & 2 deletions contrib/dev-tools/container/e2e/mysql/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,26 @@

# This script is only intended to be used for E2E testing environment.

## Index

# Database credentials
MYSQL_USER="root"
MYSQL_PASSWORD="root_secret_password"
MYSQL_HOST="127.0.0.1"
MYSQL_DATABASE="torrust_index_e2e_testing"
MYSQL_DATABASE=$TORRUST_INDEX_DATABASE

# Create the MySQL database for the index. Assumes MySQL client is installed.
# The docker compose configuration already creates the database the first time
# the container is created.
echo "Creating MySQL database $MYSQL_DATABASE for for E2E testing ..."
echo "Creating MySQL database '$MYSQL_DATABASE' for for E2E testing ..."
MYSQL_PWD=$MYSQL_PASSWORD mysql -h $MYSQL_HOST -u $MYSQL_USER -e "CREATE DATABASE IF NOT EXISTS $MYSQL_DATABASE;"

## Tracker

# Generate the Tracker sqlite database directory and file if it does not exist
mkdir -p ./storage/tracker/lib/database

if ! [ -f "./storage/tracker/lib/database/${TORRUST_TRACKER_DATABASE}.db" ]; then
echo "Creating tracker database '${TORRUST_TRACKER_DATABASE}.db'"
sqlite3 "./storage/tracker/lib/database/${TORRUST_TRACKER_DATABASE}.db" "VACUUM;"
fi
5 changes: 4 additions & 1 deletion contrib/dev-tools/container/e2e/mysql/run-e2e-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ TORRUST_TRACKER_USER_UID=$CURRENT_USER_ID
export USER_ID
export TORRUST_TRACKER_USER_UID

export TORRUST_INDEX_DATABASE="torrust_index_e2e_testing"
export TORRUST_TRACKER_DATABASE="e2e_testing_sqlite3"

# Install tool to create torrent files.
# It's needed by some tests to generate and parse test torrent files.
cargo install imdl || exit 1
Expand Down Expand Up @@ -38,7 +41,7 @@ docker ps
./contrib/dev-tools/container/e2e/mysql/install.sh || exit 1

# Run E2E tests with shared app instance
TORRUST_INDEX_E2E_SHARED=true TORRUST_INDEX_E2E_PATH_CONFIG="./share/default/config/index.container.mysql.toml" cargo test || exit 1
TORRUST_INDEX_E2E_SHARED=true TORRUST_INDEX_E2E_PATH_CONFIG="./share/default/config/index.e2e.container.mysql.toml" cargo test || exit 1

# Stop E2E testing environment
./contrib/dev-tools/container/e2e/mysql/e2e-env-down.sh || exit 1
Expand Down
4 changes: 2 additions & 2 deletions contrib/dev-tools/container/e2e/sqlite/e2e-env-down.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash

TORRUST_INDEX_CONFIG=$(cat ./share/default/config/index.container.sqlite3.toml) \
TORRUST_TRACKER_CONFIG=$(cat ./share/default/config/tracker.container.sqlite3.toml) \
TORRUST_INDEX_CONFIG=$(cat ./share/default/config/index.e2e.container.sqlite3.toml) \
TORRUST_TRACKER_CONFIG=$(cat ./share/default/config/tracker.e2e.container.sqlite3.toml) \
docker compose down
23 changes: 0 additions & 23 deletions contrib/dev-tools/container/e2e/sqlite/e2e-env-reset.sh

This file was deleted.

4 changes: 0 additions & 4 deletions contrib/dev-tools/container/e2e/sqlite/e2e-env-restart.sh

This file was deleted.

11 changes: 6 additions & 5 deletions contrib/dev-tools/container/e2e/sqlite/e2e-env-up.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#!/bin/bash

TORRUST_INDEX_CONFIG=$(cat ./share/default/config/index.container.sqlite3.toml) \
TORRUST_INDEX_CONFIG=$(cat ./share/default/config/index.e2e.container.sqlite3.toml) \
docker compose build

USER_ID=${USER_ID:-1000} \
TORRUST_INDEX_CONFIG=$(cat ./share/default/config/index.container.sqlite3.toml) \
TORRUST_INDEX_CONFIG=$(cat ./share/default/config/index.e2e.container.sqlite3.toml) \
TORRUST_INDEX_DATABASE="e2e_testing_sqlite3" \
TORRUST_INDEX_DATABASE_DRIVER="sqlite3" \
TORRUST_INDEX_TRACKER_API_TOKEN="MyAccessToken" \
TORRUST_TRACKER_CONFIG=$(cat ./share/default/config/tracker.container.sqlite3.toml) \
TORRUST_TRACKER_CONFIG=$(cat ./share/default/config/tracker.e2e.container.sqlite3.toml) \
TORRUST_TRACKER_DATABASE="e2e_testing_sqlite3" \
TORRUST_TRACKER_DATABASE_DRIVER="sqlite3" \
TORRUST_TRACKER_API_ADMIN_TOKEN="MyAccessToken" \
docker compose up -d

docker compose up --detach --pull always --remove-orphans
20 changes: 15 additions & 5 deletions contrib/dev-tools/container/e2e/sqlite/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,22 @@

# This script is only intended to be used for E2E testing environment.

# Generate storage directory if it does not exist
## Index

# Generate the Index sqlite database directory and file if it does not exist
mkdir -p ./storage/index/lib/database

# Generate the sqlite database if it does not exist
if ! [ -f "./storage/index/lib/database/sqlite3.db" ]; then
# todo: it should get the path from tracker.toml and only do it when we use sqlite
sqlite3 ./storage/index/lib/database/sqlite3.db "VACUUM;"
if ! [ -f "./storage/index/lib/database/${TORRUST_INDEX_DATABASE}.db" ]; then
echo "Creating index database '${TORRUST_INDEX_DATABASE}.db'"
sqlite3 "./storage/index/lib/database/${TORRUST_INDEX_DATABASE}.db" "VACUUM;"
fi

## Tracker

# Generate the Tracker sqlite database directory and file if it does not exist
mkdir -p ./storage/tracker/lib/database

if ! [ -f "./storage/tracker/lib/database/${TORRUST_TRACKER_DATABASE}.db" ]; then
echo "Creating tracker database '${TORRUST_TRACKER_DATABASE}.db'"
sqlite3 "./storage/tracker/lib/database/${TORRUST_TRACKER_DATABASE}.db" "VACUUM;"
fi
5 changes: 4 additions & 1 deletion contrib/dev-tools/container/e2e/sqlite/run-e2e-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ TORRUST_TRACKER_USER_UID=$CURRENT_USER_ID
export USER_ID
export TORRUST_TRACKER_USER_UID

export TORRUST_INDEX_DATABASE="e2e_testing_sqlite3"
export TORRUST_TRACKER_DATABASE="e2e_testing_sqlite3"

# Install tool to create torrent files.
# It's needed by some tests to generate and parse test torrent files.
cargo install imdl || exit 1
Expand All @@ -36,7 +39,7 @@ sleep 20s
docker ps

# Run E2E tests with shared app instance
TORRUST_INDEX_E2E_SHARED=true TORRUST_INDEX_E2E_PATH_CONFIG="./share/default/config/index.container.sqlite3.toml" cargo test || exit 1
TORRUST_INDEX_E2E_SHARED=true TORRUST_INDEX_E2E_PATH_CONFIG="./share/default/config/index.e2e.container.sqlite3.toml" cargo test || exit 1

# Stop E2E testing environment
./contrib/dev-tools/container/e2e/sqlite/e2e-env-down.sh || exit 1
13 changes: 0 additions & 13 deletions contrib/dev-tools/init/install-local.sh

This file was deleted.

2 changes: 1 addition & 1 deletion share/default/config/index.container.mysql.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ max_password_length = 64
secret_key = "MaxVerstappenWC2021"

[database]
connect_url = "mysql://root:root_secret_password@mysql:3306/torrust_index_e2e_testing"
connect_url = "mysql://root:root_secret_password@mysql:3306/torrust_index"

[mail]
email_verification_enabled = false
Expand Down
51 changes: 51 additions & 0 deletions share/default/config/index.e2e.container.mysql.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
log_level = "info"

[website]
name = "Torrust"

# Please override the tracker token setting the
# `TORRUST_INDEX_TRACKER_API_TOKEN`
# environmental variable!

[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_e2e_testing"

[mail]
email_verification_enabled = false
from = "example@email.com"
reply_to = "noreply@email.com"
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
port = 3002
51 changes: 51 additions & 0 deletions share/default/config/index.e2e.container.sqlite3.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
log_level = "info"

[website]
name = "Torrust"

# Please override the tracker token setting the
# `TORRUST_INDEX_TRACKER_API_TOKEN`
# environmental variable!

[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 = "sqlite:///var/lib/torrust/index/database/e2e_testing_sqlite3.db?mode=rwc"

[mail]
email_verification_enabled = false
from = "example@email.com"
reply_to = "noreply@email.com"
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
port = 3002
Loading

0 comments on commit c17ebbd

Please sign in to comment.