Skip to content

Commit

Permalink
Merge pull request #37 from pantheon-systems/19-integration-tests
Browse files Browse the repository at this point in the history
Configure Behat integration tests to run in CircleCI
  • Loading branch information
danielbachhuber authored Jul 23, 2019
2 parents be2b65c + ffd251a commit 12b6c38
Show file tree
Hide file tree
Showing 6 changed files with 224 additions and 0 deletions.
59 changes: 59 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
version: 2
workflows:
version: 2
main:
jobs:
- build
nightly:
triggers:
- schedule:
cron: "0 0 * * *"
filters:
branches:
only:
- master
jobs:
- build
jobs:
build:
working_directory: ~/pantheon-systems/pantheon-hud
parallelism: 1
docker:
- image: circleci/php:7.1
steps:
- checkout
- run: echo $(openssl rand -hex 8) > /tmp/WORDPRESS_ADMIN_PASSWORD
- run: |
echo 'export PATH=/tmp/terminus/bin:$PATH' >> $BASH_ENV
echo 'export TERMINUS_ENV=ci-$CIRCLE_BUILD_NUM' >> $BASH_ENV
echo 'export TERMINUS_SITE=pantheon-hud' >> $BASH_ENV
echo 'export SITE_ENV=pantheon-hud.ci-$CIRCLE_BUILD_NUM' >> $BASH_ENV
echo 'export WORDPRESS_ADMIN_USERNAME=pantheon' >> $BASH_ENV
echo 'export [email protected]' >> $BASH_ENV
echo 'export WORDPRESS_ADMIN_PASSWORD=$(cat /tmp/WORDPRESS_ADMIN_PASSWORD)' >> $BASH_ENV
source $BASH_ENV
- run: echo "StrictHostKeyChecking no" >> "$HOME/.ssh/config"
- run: |
sudo apt-get update
sudo apt-get install -y rsync
- run: |
if [ -z "$GITHUB_TOKEN" ]; then
echo "GITHUB_TOKEN environment variables missing; assuming unauthenticated build"
exit 0
fi
echo "Setting GitHub OAuth token with suppressed ouput"
{
composer config -g github-oauth.github.com $GITHUB_TOKEN
} &> /dev/null
- run: |
if [ -z "$TERMINUS_TOKEN" ]; then
echo "TERMINUS_TOKEN environment variables missing; assuming unauthenticated build"
exit 0
fi
composer install
git clone --branch master https://github.com/pantheon-systems/terminus.git /tmp/terminus
cd /tmp/terminus && composer install
terminus auth:login --machine-token=$TERMINUS_TOKEN
- run: ./bin/behat-prepare.sh
- run: ./bin/behat-test.sh --strict
- run: ./bin/behat-cleanup.sh
22 changes: 22 additions & 0 deletions behat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# behat.yml
default:
suites:
default:
paths:
- tests/behat
contexts:
- Behat\MinkExtension\Context\MinkContext
- PantheonSystems\PantheonWordPressUpstreamTests\Behat\AdminLogIn
core:
filters:
tags: "~@upstreamonly"
paths:
- vendor/pantheon-systems/pantheon-wordpress-upstream-tests/features
contexts:
- Behat\MinkExtension\Context\MinkContext
- PantheonSystems\PantheonWordPressUpstreamTests\Behat\AdminLogIn
- PantheonSystems\PantheonWordPressUpstreamTests\Behat\ResponseHeader
extensions:
Behat\MinkExtension:
# base_url set by ENV
goutte: ~
23 changes: 23 additions & 0 deletions bin/behat-cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

###
# Delete the Pantheon site environment after the Behat test suite has run.
###

terminus whoami > /dev/null
if [ $? -ne 0 ]; then
echo "Terminus unauthenticated; assuming unauthenticated build"
exit 0
fi

set -ex

if [ -z "$TERMINUS_SITE" ] || [ -z "$TERMINUS_ENV" ]; then
echo "TERMINUS_SITE and TERMINUS_ENV environment variables must be set"
exit 1
fi

###
# Delete the environment used for this test run.
###
terminus multidev:delete $SITE_ENV --delete-branch --yes
82 changes: 82 additions & 0 deletions bin/behat-prepare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/bin/bash

###
# Prepare a Pantheon site environment for the Behat test suite, by installing
# and configuring the plugin for the environment. This script is architected
# such that it can be run a second time if a step fails.
###

terminus whoami > /dev/null
if [ $? -ne 0 ]; then
echo "Terminus unauthenticated; assuming unauthenticated build"
exit 0
fi

if [ -z "$TERMINUS_SITE" ] || [ -z "$TERMINUS_ENV" ]; then
echo "TERMINUS_SITE and TERMINUS_ENV environment variables must be set"
exit 1
fi

if [ -z "$WORDPRESS_ADMIN_USERNAME" ] || [ -z "$WORDPRESS_ADMIN_PASSWORD" ]; then
echo "WORDPRESS_ADMIN_USERNAME and WORDPRESS_ADMIN_PASSWORD environment variables must be set"
exit 1
fi

set -ex

###
# Create a new environment for this particular test run.
###
terminus env:create $TERMINUS_SITE.dev $TERMINUS_ENV
terminus env:wipe $SITE_ENV --yes

###
# Get all necessary environment details.
###
PANTHEON_GIT_URL=$(terminus connection:info $SITE_ENV --field=git_url)
PANTHEON_SITE_URL="$TERMINUS_ENV-$TERMINUS_SITE.pantheonsite.io"
PREPARE_DIR="/tmp/$TERMINUS_ENV-$TERMINUS_SITE"
BASH_DIR="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

###
# Switch to git mode for pushing the files up
###
terminus connection:set $SITE_ENV git
rm -rf $PREPARE_DIR
git clone -b $TERMINUS_ENV $PANTHEON_GIT_URL $PREPARE_DIR

###
# Add the copy of this plugin itself to the environment
###
rm -rf $PREPARE_DIR/wp-content/plugins/pantheon-hud
cd $BASH_DIR/..
rsync -av --exclude='vendor/' --exclude='node_modules/' --exclude='tests/' ./* $PREPARE_DIR/wp-content/plugins/pantheon-hud
rm -rf $PREPARE_DIR/wp-content/plugins/pantheon-hud/.git

# Download the latest Classic Editor release from WordPress.org
wget -O $PREPARE_DIR/classic-editor.zip https://downloads.wordpress.org/plugin/classic-editor.zip
unzip $PREPARE_DIR/classic-editor.zip -d $PREPARE_DIR
mv $PREPARE_DIR/classic-editor $PREPARE_DIR/wp-content/plugins/
rm $PREPARE_DIR/classic-editor.zip

###
# Push files to the environment
###
cd $PREPARE_DIR
git add wp-content
git config user.email "[email protected]"
git config user.name "Pantheon"
git commit -m "Include Pantheon HUD and its configuration files"
git push

###
# Set up WordPress, theme, and plugins for the test run
###
# Silence output so as not to show the password.
{
terminus wp $SITE_ENV -- core install --title=$TERMINUS_ENV-$TERMINUS_SITE --url=$PANTHEON_SITE_URL --admin_user=$WORDPRESS_ADMIN_USERNAME [email protected] --admin_password=$WORDPRESS_ADMIN_PASSWORD
} &> /dev/null
terminus wp $SITE_ENV -- cache flush
terminus wp $SITE_ENV -- plugin activate pantheon-hud classic-editor
terminus wp $SITE_ENV -- theme activate twentyseventeen
terminus wp $SITE_ENV -- rewrite structure '/%year%/%monthnum%/%day%/%postname%/'
27 changes: 27 additions & 0 deletions bin/behat-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

###
# Execute the Behat test suite against a prepared Pantheon site environment.
###

terminus whoami > /dev/null
if [ $? -ne 0 ]; then
echo "Terminus unauthenticated; assuming unauthenticated build"
exit 0
fi

if [ -z "$TERMINUS_SITE" ] || [ -z "$TERMINUS_ENV" ]; then
echo "TERMINUS_SITE and TERMINUS_ENV environment variables must be set"
exit 1
fi

if [ -z "$WORDPRESS_ADMIN_USERNAME" ] || [ -z "$WORDPRESS_ADMIN_PASSWORD" ]; then
echo "WORDPRESS_ADMIN_USERNAME and WORDPRESS_ADMIN_PASSWORD environment variables must be set"
exit 1
fi

set -ex

export BEHAT_PARAMS='{"extensions" : {"Behat\\MinkExtension" : {"base_url" : "http://'$TERMINUS_ENV'-'$TERMINUS_SITE'.pantheonsite.io"} }}'

./vendor/bin/behat "$@"
11 changes: 11 additions & 0 deletions tests/behat/pantheon-hud.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Feature: Solr Power plugin

Background:
Given I log in as an admin

Scenario: Plugin is loaded
When I go to "/wp-admin/"
Then the "#wp-admin-bar-pantheon-hud" element should contain "pantheon-hud.pantheonsite.io"
And the "#wp-admin-bar-pantheon-hud" element should contain "1 app container running PHP"
And the "#wp-admin-bar-pantheon-hud" element should contain "1 db container with replication disabled"
And the "#wp-admin-bar-pantheon-hud" element should contain "Visit Pantheon Dashboard"

0 comments on commit 12b6c38

Please sign in to comment.