-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Define integration test config override, which basically renames all the volumes to avoid clashing with any existing volumes. - Add test setup, which starts all the services and installs mediawiki using the CLI installer. - Add an example test, which loads the Main Page. More to come. - Add integration tests to the Travis CI config.
- Loading branch information
Showing
5 changed files
with
141 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
MYSQL_PASSWORD=db_password | ||
MAILGUN_PASSWORD= | ||
RECAPTCHA_SECRET_KEY= | ||
WG_SECRET_KEY= | ||
SITE_UPGRADE_KEY= | ||
SERVER_PORT= | ||
SERVER_NAME= | ||
DROPBOX_ACCESS_TOKEN= |
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,22 @@ | ||
version: '2.1' | ||
|
||
services: | ||
mysql: | ||
volumes: | ||
- db-test-volume:/var/lib/mysql | ||
nginx: | ||
volumes: | ||
- mediawiki-test-volume:/srv/mediawiki | ||
ports: | ||
- "80" | ||
php: | ||
volumes: | ||
- mediawiki-test-volume:/srv/mediawiki | ||
mediawiki: | ||
volumes: | ||
- mediawiki-test-volume:/srv/mediawiki | ||
|
||
volumes: | ||
mediawiki-test-volume: | ||
db-test-volume: | ||
images-test-volume: |
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,98 @@ | ||
#!/usr/bin/env bash | ||
|
||
RED='\033[1;31m' | ||
GREEN='\033[1;32m' | ||
YELLOW='\033[1;33m' | ||
NC='\033[0m' # No Color | ||
|
||
set -xe | ||
|
||
REPO_ROOT=$(git rev-parse --show-toplevel) | ||
TEST_ROOT="$REPO_ROOT/test/integration" | ||
DOCKER_CONFIG="-f $REPO_ROOT/docker-compose.yml -f $TEST_ROOT/docker-compose.test.yml" | ||
DOCKER_COMPOSE="docker-compose $DOCKER_CONFIG" | ||
WIKI="/srv/mediawiki" | ||
|
||
cd $TEST_ROOT | ||
source .env | ||
|
||
function info { | ||
echo -e "${YELLOW}$1${NC}" | ||
} | ||
|
||
function error { | ||
echo -e "${RED}$1${NC}" | ||
exit 1 | ||
} | ||
|
||
function cleanup { | ||
EXIT_CODE=$? | ||
|
||
if [[ $EXIT_CODE != 0 && $($DOCKER_COMPOSE top) != "" ]]; then | ||
info "Dumping logs" | ||
$DOCKER_COMPOSE logs | ||
fi | ||
|
||
info "Cleaning up" | ||
$DOCKER_COMPOSE down --volumes | ||
|
||
if [[ $EXIT_CODE == 0 ]]; then | ||
echo -e "${GREEN}All tests passed.${NC}" | ||
else | ||
echo -e "${RED}Test failure(s)!${NC}" | ||
fi | ||
|
||
exit $EXIT_CODE | ||
} | ||
|
||
info "Making sure no services are running" | ||
if [[ $($DOCKER_COMPOSE top) != "" ]]; then | ||
error "Cannot run integration tests while services are running. Run 'docker-compose down' and try again." | ||
fi | ||
|
||
# About to start tests; make sure we clean up afterwards | ||
trap cleanup EXIT | ||
|
||
info "Starting integration test services" | ||
$DOCKER_COMPOSE up --build -d 1>/dev/null | ||
info "Waiting for mysql to initialize" | ||
for i in {1..24}; do | ||
if [[ $($DOCKER_COMPOSE logs mysql | grep "ready for connections") != "" ]]; then | ||
sleep 15 # to be extra-sure that mysql is ready | ||
break | ||
fi | ||
sleep 5 | ||
if [[ $i == 24 ]]; then | ||
error "mysql failed to initialise within 120 seconds" | ||
fi | ||
done | ||
|
||
# Find the random port that nginx is mapped to | ||
NGINX_ADDR=$(docker-compose port nginx 80) | ||
|
||
info "Initializing database" | ||
# Move LocalSettings.php out of the way otherwise the installer complains | ||
$DOCKER_COMPOSE exec php mv $WIKI/LocalSettings.php $WIKI/LocalSettings.php.bak | ||
$DOCKER_COMPOSE exec php php $WIKI/maintenance/install.php \ | ||
--confpath /tmp \ | ||
--dbname metakgp_wiki_db \ | ||
--dbserver mysql-docker \ | ||
--dbuser metakgp_user \ | ||
--dbpass $MYSQL_PASSWORD \ | ||
--installdbuser metakgp_user \ | ||
--installdbpass $MYSQL_PASSWORD \ | ||
--pass admin_password \ | ||
--scriptpath "" \ | ||
Metakgp Test Wiki \ | ||
Admin | ||
|
||
# Move LocalSettings.php back in place | ||
$DOCKER_COMPOSE exec php mv $WIKI/LocalSettings.php.bak $WIKI/LocalSettings.php | ||
|
||
# Sample test only; more comprehensive tests to follow | ||
CURL_OUTPUT=$(curl -sSL $NGINX_ADDR) | ||
if [[ $CURL_OUTPUT != *"Powered by MediaWiki"* ]]; then | ||
error "Main page failed to load properly: "$CURL_OUTPUT | ||
fi | ||
|
||
info "Tests complete" |
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,11 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -xe | ||
|
||
REPO_ROOT=$(git rev-parse --show-toplevel) | ||
|
||
# Verify that builds succeed | ||
docker-compose build | ||
|
||
# Run integration tests | ||
$REPO_ROOT/test/integration/run_tests.sh |