Skip to content

Commit

Permalink
chore:update local tests
Browse files Browse the repository at this point in the history
Refs: OPS-9227
  • Loading branch information
orakili committed Sep 16, 2023
1 parent 2cc0fae commit a718b0f
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 46 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Variables. Yes.
DOCKER=docker
DOCKER_BUILDKIT=0
IMAGE_NAME=starterkit-site
IMAGE_TAG=local

# The main build recipe.
build: clean
Expand All @@ -12,7 +14,7 @@ build: clean
--build-arg GITHUB_ACTOR=`whoami` \
--build-arg GITHUB_REPOSITORY=`git config --get remote.origin.url` \
--build-arg GITHUB_SHA=`git rev-parse --short HEAD` \
. --file docker/Dockerfile --tag public.ecr.aws/unocha/starterkit-site:local \
. --file docker/Dockerfile --tag public.ecr.aws/unocha/$(IMAGE_NAME):$(IMAGE_TAG) \
2>&1 | tee buildlog.txt

clean:
Expand Down
40 changes: 19 additions & 21 deletions tests/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
version: "2.2"
name: starterkit-test

networks:
default:

volumes:
starterkit-test-site-database:
starterkit-test-site-public:
starterkit-test-site-private:
site-public:
site-private:

services:
memcache:
restart: always
image: public.ecr.aws/unocha/memcache:1.6
hostname: starterkit-test-memcache
container_name: starterkit-test-memcache
environment:
MEMCACHE_MAX_MEMORY: 64
ports:
- "11211"
networks:
- default
environment:
MEMCACHE_MAX_MEMORY: 64

mysql:
image: public.ecr.aws/unocha/mysql:10.6
hostname: starterkit-test-mysql
container_name: starterkit-test-mysql
environment:
- MYSQL_DB=starterkit
- MYSQL_USER=starterkit
- MYSQL_PASS=starterkit
volumes:
- "starterkit-test-site-database:/var/lib/mysql:rw"
- MYSQL_DB=reliefweb
- MYSQL_USER=reliefweb
- MYSQL_PASS=reliefweb
networks:
- default

drupal:
image: public.ecr.aws/unocha/starterkit-site:local
# Default to `starterkit-site` for compatibility with the github tests.
# @see Makefile.
image: public.ecr.aws/unocha/${IMAGE_NAME:-starterkit-site}:${IMAGE_TAG:-local}
hostname: starterkit-test-site
container_name: starterkit-test-site
depends_on:
Expand All @@ -44,29 +44,27 @@ services:
volumes:
- "./settings:/srv/www/shared/settings:ro"
# Mount volumes for the private and public files.
- "starterkit-test-site-public:/srv/www/html/sites/default/files:rw"
- "starterkit-test-site-private:/srv/www/html/sites/default/private:rw"
- "site-public:/srv/www/html/sites/default/files:rw"
- "site-private:/srv/www/html/sites/default/private:rw"
# Mount the folders needed for the tests.
- "../phpcs.xml:/srv/www/phpcs.xml:ro"
- "../phpunit.xml:/srv/www/phpunit.xml:ro"
- "../.coveralls.yml:/srv/www/.coveralls.yml:ro"
# Mount local custom code.
#- "../html/modules/custom:/srv/www/html/modules/custom:ro"
#- "../html/themes/custom:/srv/www/html/themes/custom:ro"
- "../html/modules/custom:/srv/www/html/modules/custom:ro"
- "../html/themes/custom:/srv/www/html/themes/custom:ro"
environment:
- TERM=xterm
- ENVIRONMENT=dev
- NGINX_SERVERNAME=starterkit-test-site,localhost,127.0.0.1
- NGINX_OVERRIDE_PROTOCOL=HTTP,starterkit-test-site,localhost,127.0.0.1
- DRUSH_OPTIONS_URI=http://starterkit-test-site
- DRUPAL_DB_DATABASE=starterkit
- DRUPAL_DB_USERNAME=starterkit
- DRUPAL_DB_PASSWORD=starterkit
- DRUPAL_DB_DATABASE=reliefweb
- DRUPAL_DB_USERNAME=reliefweb
- DRUPAL_DB_PASSWORD=reliefweb
- DRUPAL_DB_HOST=mysql
- DRUPAL_DB_DRIVER=mysql
- PHP_ENVIRONMENT=dev
- PHP_XDEBUG=true
- XDEBUG_MODE=coverage
- BROWSERTEST_OUTPUT_DIRECTORY=/srv/www/html/sites/default/files/browser_output
- DTT_BASE_URL=http://127.0.0.1
networks:
- default
4 changes: 2 additions & 2 deletions tests/settings/settings.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
$settings['config_sync_directory'] = '/srv/www/config';

// Hash salt.
$settings['hash_salt'] = 'starterkit-test-site-salt';
$settings['hash_salt'] = 'test-site-salt';

// Memcache.
if (file_exists('sites/default/memcache.services.yml')) {
Expand All @@ -158,7 +158,7 @@
// Configure memcache.
$settings['memcache']['servers'] = ['memcache:11211' => 'default'];
$settings['memcache']['bins'] = ['default' => 'default'];
$settings['memcache']['key_prefix'] = 'starterkit-test';
$settings['memcache']['key_prefix'] = 'test';
$settings['cache']['default'] = 'cache.backend.memcache';

// Performance tweaks.
Expand Down
55 changes: 33 additions & 22 deletions tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,64 @@

# This is the equivalent of the tests in `.travis.yml` that can be run locally.

IMAGE_NAME=starterkit-test
IMAGE_TAG=test

function cleanup() {
echo "Removing test containers"
docker compose -f tests/docker-compose.yml down
echo "Removing test images"
docker rmi public.ecr.aws/unocha/$IMAGE_NAME:$IMAGE_TAG || true
}

trap cleanup ABRT EXIT HUP INT QUIT TERM

# Remove previous containers.
cleanup

# Build local image.
echo "Build local image."
make
make IMAGE_NAME=$IMAGE_NAME IMAGE_TAG=$IMAGE_TAG

# Create the site, memcache and mysql containers.
echo "Create the site, memcache and mysql containers."
docker-compose -p starterkit-test -f tests/docker-compose.yml up -d
IMAGE_NAME=$IMAGE_NAME IMAGE_TAG=$IMAGE_TAG docker compose -f tests/docker-compose.yml up -d

# Dump some information about the created containers.
echo "Dump some information about the created containers."
docker ps -a -fname=starterkit-test
docker compose -f tests/docker-compose.yml ps -a

# Wait a bit for memcache and mysql to be ready.
echo "Wait a bit for memcache and mysql to be ready."
sleep 10

# Ensure the file directories are writable.
echo "Ensure the file directories are writable."
docker exec -it starterkit-test-site chmod -R 777 /srv/www/html/sites/default/files /srv/www/html/sites/default/private

# Install the common design subtheme.
echo "Make sure the common design subtheme is installed"
docker exec -it -w /srv/www starterkit-test-site composer run sub-theme
# Install the dev dependencies.
echo "docker compose -f tests/docker-compose.yml exec -w /srv/www drupal composer install"
docker compose -f tests/docker-compose.yml exec -w /srv/www drupal composer install

# Check coding standards.
echo "Check coding standards."
docker exec -it -u appuser -w /srv/www starterkit-test-site ./vendor/bin/phpcs -p --report=full ./html/modules/custom ./html/themes/custom
docker compose -f tests/docker-compose.yml exec -u appuser -w /srv/www drupal ./vendor/bin/phpcs -p --report=full ./html/modules/custom ./html/themes/custom

# Run unit tests.
echo "Run unit tests."
docker exec -it -u root -w /srv/www starterkit-test-site mkdir -p /srv/www/html/sites/default/files/browser_output
docker exec -it -u root -w /srv/www -e BROWSERTEST_OUTPUT_DIRECTORY=/srv/www/html/sites/default/files/browser_output starterkit-test-site php -d zend_extension=xdebug ./vendor/bin/phpunit --testsuite Unit --debug
docker compose -f tests/docker-compose.yml exec -u root -w /srv/www drupal mkdir -p /srv/www/html/sites/default/files/browser_output
docker compose -f tests/docker-compose.yml exec -u root -w /srv/www -e BROWSERTEST_OUTPUT_DIRECTORY=/srv/www/html/sites/default/files/browser_output drupal php -d zend_extension=xdebug ./vendor/bin/phpunit --testsuite Unit --debug

# Install the site with the existing config.
echo "Install the site with the existing config."
docker exec -it starterkit-test-site drush -y si --existing-config minimal install_configure_form.enable_update_status_emails=NULL
docker exec -it starterkit-test-site drush -y en dblog
docker compose -f tests/docker-compose.yml exec drupal drush -y si --existing-config
docker compose -f tests/docker-compose.yml exec drupal drush -y en dblog

# Ensure the file directories are writable.
echo "Ensure the file directories are writable."
docker compose -f tests/docker-compose.yml exec drupal chmod -R 777 /srv/www/html/sites/default/files /srv/www/html/sites/default/private

# Create the build logs directory and make sure it's writable.
echo "Create the build logs directory and make sure it's writable."
docker exec -it -u root starterkit-test-site mkdir -p /srv/www/html/build/logs
docker exec -it -u root starterkit-test-site chmod -R 777 /srv/www/html/build/logs
docker compose -f tests/docker-compose.yml exec -u root drupal mkdir -p /srv/www/html/build/logs
docker compose -f tests/docker-compose.yml exec -u root drupal chmod -R 777 /srv/www/html/build/logs

# Run all tests and generate coverage report.
echo "Run all tests and generate coverage report."
docker exec -it -u root -w /srv/www -e XDEBUG_MODE=coverage -e BROWSERTEST_OUTPUT_DIRECTORY=/srv/www/html/sites/default/files/browser_output -e DTT_BASE_URL=http://127.0.0.1 starterkit-test-site php -d zend_extension=xdebug ./vendor/bin/phpunit --coverage-clover /srv/www/html/build/logs/clover.xml --debug

# Remove the image.
echo "Remove the test image"
docker-compose -p starterkit-test -f tests/docker-compose.yml down -v
docker compose -f tests/docker-compose.yml exec -u root -w /srv/www -e XDEBUG_MODE=coverage -e BROWSERTEST_OUTPUT_DIRECTORY=/srv/www/html/sites/default/files/browser_output -e DTT_BASE_URL=http://127.0.0.1 drupal php -d zend_extension=xdebug ./vendor/bin/phpunit --coverage-clover /srv/www/html/build/logs/clover.xml --debug

0 comments on commit a718b0f

Please sign in to comment.