Skip to content
This repository has been archived by the owner on Feb 13, 2023. It is now read-only.

Commit

Permalink
Issue #1206: Is it possible this will work? Everything is composer ru…
Browse files Browse the repository at this point in the history
…n-tests
  • Loading branch information
geerlingguy committed Apr 29, 2017
1 parent 39d84cc commit 1ff0768
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 62 deletions.
81 changes: 36 additions & 45 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
language: php
php: '7.1'
services: docker

env:
Expand All @@ -12,64 +14,53 @@ env:
DRUPALVM_DIR: /var/www/drupalvm
DRUSH_BIN: drush
TEST_INSTALLED_EXTRAS: true
CONTAINER_ID: dvm-test

matrix:
# Defaults - Ubuntu 16.04.
- type: defaults
distro: ubuntu1604
init: /sbin/init
run_opts: "--privileged"
# # Defaults - Ubuntu 14.04.
# - type: defaults
# distro: ubuntu1404
# init: /sbin/init
# run_opts: "--privileged"
# # PHP 5.6 - Ubuntu 16.04.
# - type: defaults
# distro: ubuntu1604
# init: /sbin/init
# run_opts: "--privileged"
# local_config: tests/ubuntu-16-php56.config.yml
# DRUSH_BIN: "${DRUPALVM_DIR}/drupal/vendor/drush/drush/drush"
# TEST_INSTALLED_EXTRAS: false
# # Nginx and Drush make file test - Ubuntu 16.04.
# - type: nginx-drush-make
# distro: ubuntu1604
# init: /sbin/init
# run_opts: "--privileged"
# local_config: tests/ubuntu-16-nginx.config.yml
# config_dir: /var/www/drupalvm/config
# # PostgreSQL - Ubuntu 16.04.
# - type: postgresql
# distro: ubuntu1604
# init: /sbin/init
# run_opts: "--privileged"
# local_config: tests/ubuntu-16-postgresql.config.yml
# config_dir: /var/www/drupalvm/config
# DRUSH_BIN: "${DRUPALVM_DIR}/drupal/vendor/drush/drush/drush"
# TEST_INSTALLED_EXTRAS: false
# # Defaults - CentOS 7.
# - type: centos
# distro: centos7
# init: /usr/lib/systemd/systemd
# run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
# # Defaults - Debian 8.
# - type: debian
# distro: debian8
# init: /lib/systemd/systemd
# run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
# Defaults - Ubuntu 14.04.
- type: defaults
distro: ubuntu1404
# Defaults - CentOS 7.
- type: centos
distro: centos7
# Defaults - Debian 8.
- type: debian
distro: debian8

# PHP 5.6 - Ubuntu 16.04.
- type: defaults
distro: ubuntu1604
local_config: tests/ubuntu-16-php56.config.yml
DRUSH_BIN: "${DRUPALVM_DIR}/drupal/vendor/drush/drush/drush"
TEST_INSTALLED_EXTRAS: false

# Nginx and Drush make file test - Ubuntu 16.04.
- type: nginx-drush-make
distro: ubuntu1604
local_config: tests/ubuntu-16-nginx.config.yml
config_dir: /var/www/drupalvm/config

# PostgreSQL - Ubuntu 16.04.
- type: postgresql
distro: ubuntu1604
local_config: tests/ubuntu-16-postgresql.config.yml
config_dir: /var/www/drupalvm/config
DRUSH_BIN: "${DRUPALVM_DIR}/drupal/vendor/drush/drush/drush"
TEST_INSTALLED_EXTRAS: false

before_install:
# Pull container.
- 'docker pull geerlingguy/docker-${distro}-ansible:latest'
- docker pull geerlingguy/docker-${distro}-ansible:latest

# Install lint tools.
- 'gem install rubocop'
- gem install rubocop

script:
# Vagrantfile syntax check.
- 'rubocop ./Vagrantfile ./lib/drupalvm --except LineLength,Eval,MutableConstant,BlockLength,ConditionalAssignment,IndentArray,AlignParameters'

# Try something quite radical.
# Run tests.
- composer run-tests

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ To run basic integration tests using Docker:
1. [Install Docker](https://docs.docker.com/engine/installation/).
2. In this project directory, run: `composer run-tests`

> Note: If you're on a Mac, and want to use Docker's `cached` volume option (or `delegated`, once it's available) for faster local filesystem access, you need to install [Docker's Edge release](https://docs.docker.com/docker-for-mac/install/#download-docker-for-mac).
> Note: If you're on a Mac, you need to use [Docker's Edge release](https://docs.docker.com/docker-for-mac/install/#download-docker-for-mac), at least until [this issue](https://github.com/docker/for-mac/issues/77) is resolved.
The project's automated tests are run via Travis CI, and the more comprehensive test suite covers multiple Linux distributions and many different Drupal VM use cases and deployment techniques.

Expand Down
162 changes: 146 additions & 16 deletions tests/run-tests.sh
Original file line number Diff line number Diff line change
@@ -1,39 +1,169 @@
#!/bin/bash
#
# A script to run Drupal VM functional tests.

# Set volume options.
# Set defaults if they're not set upstream.
CONFIG="${CONFIG:-tests/config.yml}"
MAKEFILE="${MAKEFILE:-example.drupal.make.yml}"
COMPOSERFILE="${COMPOSERFILE:-example.drupal.composer.json}"
HOSTNAME="${HOSTNAME:-drupalvm.dev}"
MACHINE_NAME="${MACHINE_NAME:-drupalvm}"
IP="${IP:-192.168.88.88}"
DRUPALVM_DIR="${DRUPALVM_DIR:-/var/www/drupalvm}"
DRUSH_BIN="${DRUSH_BIN:-drush}"
TEST_INSTALLED_EXTRAS="${TEST_INSTALLED_EXTRAS:-true}"
CONTAINER_ID="${CONTAINER_ID:-dvm-test}"
type="${type:-tests/defaults}"
distro="${distro:-ubuntu1604}"

## Set up vars for Docker setup.
# CentOS 7
if [ $distro = 'centos7' ]; then
init="/usr/lib/systemd/systemd"
opts="--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
# CentOS 6
elif [ $distro = 'centos6' ]; then
init="/sbin/init"
opts="--privileged"
# Ubuntu 16.04
elif [ $distro = 'ubuntu1604' ]; then
init="/lib/systemd/systemd"
opts="--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
# Ubuntu 14.04
elif [ $distro = 'ubuntu1404' ]; then
init="/sbin/init"
opts="--privileged"
# Ubuntu 12.04
elif [ $distro = 'ubuntu1204' ]; then
init="/sbin/init"
opts="--privileged"
# Debian 8
elif [ $distro = 'debian8' ]; then
init="/lib/systemd/systemd"
opts="--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
# Fedora 24
elif [ $distro = 'fedora24' ]; then
init="/usr/lib/systemd/systemd"
opts="--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
fi

# Set OS-specific options.
if [[ "$OSTYPE" == "darwin"* ]]; then
volume_opts='rw,cached'
xargs_command='xargs'
else
volume_opts='rw'
xargs_command='xargs -r'
fi

# Exit on any individual command failure.
set -e

# Pretty colors.
red='\033[0;31m'
green='\033[0;32m'
neutral='\033[0m'

# Remove test container if it already exists.
docker ps -aq --filter name=dvm-test | xargs docker rm -f -v
printf "\n"${green}"Removing any existing test containers..."${neutral}"\n"
docker ps -aq --filter name=$CONTAINER_ID | $xargs_command docker rm -f -v
printf ${green}"...done!"${neutral}"\n"

# Run the container.
docker run --name=dvm-test -d \
printf "\n"${green}"Starting Docker container: geerlingguy/docker-$distro-ansible."${neutral}"\n"
docker run --name=$CONTAINER_ID -d \
--add-host "$HOSTNAME drupalvm":127.0.0.1 \
-v $PWD:/var/www/drupalvm/:$volume_opts \
-p 8888:80 \
--privileged \
geerlingguy/docker-ubuntu1604-ansible:latest \
/lib/systemd/systemd
$opts \
geerlingguy/docker-$distro-ansible:latest \
$init

# Create Drupal directory.
docker exec dvm-test mkdir -p /var/www/drupalvm/drupal
# Set up directories.
docker exec $CONTAINER_ID mkdir -p /var/www/drupalvm/drupal
[[ ! -z "$config_dir" ]] && docker exec $CONTAINER_ID mkdir -p $config_dir || true

# Copy configuration into place.
docker exec $CONTAINER_ID cp $DRUPALVM_DIR/$CONFIG ${config_dir:-$DRUPALVM_DIR}/config.yml
docker exec $CONTAINER_ID cp $DRUPALVM_DIR/$MAKEFILE ${config_dir:-$DRUPALVM_DIR}/drupal.make.yml
docker exec $CONTAINER_ID cp $DRUPALVM_DIR/$COMPOSERFILE ${config_dir:-$DRUPALVM_DIR}/drupal.composer.json
[[ ! -z "$DRUPALVM_ENV" ]] && docker exec $CONTAINER_ID bash -c "cp $DRUPALVM_DIR/tests/$DRUPALVM_ENV.config.yml ${config_dir:-$DRUPALVM_DIR}/$DRUPALVM_ENV.config.yml" || true

# Override configuration variables with local config.
[[ ! -z "$local_config" ]] && docker exec $CONTAINER_ID bash -c "cp $DRUPALVM_DIR/$local_config ${config_dir:-$DRUPALVM_DIR}/local.config.yml" || true

# Check playbook syntax.
docker exec --tty dvm-test env TERM=xterm ansible-playbook /var/www/drupalvm/provisioning/playbook.yml --syntax-check
printf "\n"${green}"Checking playbook syntax..."${neutral}"\n"
docker exec --tty $CONTAINER_ID env TERM=xterm ansible-playbook $DRUPALVM_DIR/provisioning/playbook.yml --syntax-check

# Run the setup playbook.
printf "\n"${green}"Running the setup playbook..."${neutral}"\n"
docker exec --tty $CONTAINER_ID env TERM=xterm ansible-playbook /var/www/drupalvm/tests/test-setup.yml

# Set things up and run the Ansible playbook.
docker exec --tty dvm-test env TERM=xterm ansible-playbook /var/www/drupalvm/tests/test-setup.yml
docker exec dvm-test env TERM=xterm ANSIBLE_FORCE_COLOR=true COMPOSER_PROCESS_TIMEOUT=1800 ansible-playbook /var/www/drupalvm/provisioning/playbook.yml
# Run the Drupal VM playbook.
printf "\n"${green}"Running the Drupal VM playbook..."${neutral}"\n"
if [ ! -z "${config_dir}" ]; then
# Run with config_dir specified.
docker exec $CONTAINER_ID env TERM=xterm ANSIBLE_FORCE_COLOR=true DRUPALVM_ENV=$DRUPALVM_ENV \
ansible-playbook $DRUPALVM_DIR/provisioning/playbook.yml \
--extra-vars="config_dir=$config_dir";
else
# Run without config_dir specified.
docker exec $CONTAINER_ID env TERM=xterm ANSIBLE_FORCE_COLOR=true DRUPALVM_ENV=$DRUPALVM_ENV \
ansible-playbook $DRUPALVM_DIR/provisioning/playbook.yml;
fi

# Check if Drupal was installed successfully.
docker exec dvm-test curl -s --header Host:$HOSTNAME localhost \
# Drupal.
printf "\n"${green}"Running functional tests..."${neutral}"\n"
docker exec $CONTAINER_ID curl -s --header Host:$HOSTNAME localhost \
| grep -q '<title>Welcome to Drupal' \
&& (echo 'Drupal install pass' && exit 0) \
|| (echo 'Drupal install fail' && exit 1)

# Adminer.
if [ $TEST_INSTALLED_EXTRAS = true ]; then
docker exec $CONTAINER_ID curl -s --header Host:adminer.$HOSTNAME localhost \
| grep -q '<title>Login - Adminer' \
&& (echo 'Adminer install pass' && exit 0) \
|| (echo 'Adminer install fail' && exit 1)
fi

# Pimp My Log.
if [ $TEST_INSTALLED_EXTRAS = true ]; then
docker exec $CONTAINER_ID curl -s --header Host:pimpmylog.$HOSTNAME localhost \
| grep -q '<title>Pimp my Log' \
&& (echo 'Pimp my Log install pass' && exit 0) \
|| (echo 'Pimp my Log install fail' && exit 1)
fi

# MailHog.
if [ $TEST_INSTALLED_EXTRAS = true ]; then
docker exec $CONTAINER_ID curl -s localhost:8025 \
| grep -q '<title>MailHog' \
&& (echo 'MailHog install pass' && exit 0) \
|| (echo 'MailHog install fail' && exit 1)
fi

# Varnish.
if [ $TEST_INSTALLED_EXTRAS = true ]; then
docker exec $CONTAINER_ID curl -sI --header Host:$HOSTNAME localhost:81 \
| grep -q 'Via: .* varnish' \
&& (echo 'Varnish install pass' && exit 0) \
|| (echo 'Varnish install fail' && exit 1)
fi

# Dashboard.
docker exec $CONTAINER_ID curl -s --header Host:$IP localhost
| grep -q "<li>$IP $HOSTNAME</li>"
&& (echo 'Dashboard install pass' && exit 0)
|| (echo 'Dashboard install fail' && exit 1)

# Drush.
docker exec $CONTAINER_ID $DRUSH_BIN @$MACHINE_NAME.$HOSTNAME status
| grep -q 'Drupal bootstrap.*Successful'
&& (echo 'Drush install pass' && exit 0)
|| (echo 'Drush install fail' && exit 1)

# Remove test container.
docker rm -f dvm-test
printf "\n"${green}"Cleaning up..."${neutral}"\n"
docker rm -f $CONTAINER_ID
printf ${green}"...done!"${neutral}"\n\n"

0 comments on commit 1ff0768

Please sign in to comment.