Actions

Testing/Behat Testing/Run Behat On Docker

From Mahara Wiki

< Testing/Behat Testing
Revision as of 15:09, 11 October 2016 by Sonn (talk | contribs) (Run mahara container)

You can use docker to run mahara behat tests on your local machine without concern for os, php or firefox compatibility. Using docker, you can run the tests on your Linux, Windows or Mac machine.

Install Docker on your machine

Please read more detailed information for Mac users and for Windows users.

Here are a quick start for Ubuntu users

Install Docker on Ubuntu machine

These instructions are for Ubuntu 14.04 and 16.04 You should have sudo privilege to install.

Update your apt sources

  • Update package info
$ sudo apt-get update
$ sudo apt-get install apt-transport-https ca-certificates
  • Add the new GPG key for Docker’s APT repository
$ sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
  • Add an line for your Ubuntu to the /etc/apt/sources.list.d/docker.list file
    • On Ubuntu Trusty 14.04 (LTS)
$ sudo bash -c 'echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" >> /etc/apt/sources.list.d/docker.list'
    • On Ubuntu Xenial 16.04 (LTS)
$ sudo bash -c 'echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" >> /etc/apt/sources.list.d/docker.list'
  • Update the APT package index and verify APT repository for docker
$ sudo apt-get update
$ apt-cache policy docker-engine

Install linux-image-extra-* packages

$ sudo apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual
$ sudo reboot

Install docker

$ sudo apt-get install docker-engine
$ sudo service docker start

Docker images for mahara developers and testers

Catalyst Docker Registry

All internal docker images should be pulled/pushed from/to our catalyst private registry. If you don't have a login credential on it, please make a new request on the WR #245259.

Login to catalyst docker registry

$ sudo docker login https://cat-prod-dockerregistry.catalyst.net.nz
Username (<your username>): 
Password: 
Login Succeeded
$ sudo docker info

Pull mahara docker images

$ sudo docker pull cat-prod-dockerregistry.catalyst.net.nz/sonn/mahara-dev:trusty64-apache24-php55-postgres-firefox45

The image name 'cat-prod-dockerregistry.catalyst.net.nz/sonn/mahara-dev:trusty64-apache24-php55-postgres-firefox45' will be the default image when run the script run_mahara_container.sh

Mahara docker images on seafile

For those who haven't got access to catalyst docker registry, the images are available to download via catalyst seafile

  • Download the file ubuntu1404_lappf.tar from catalyst seafile
  • Load it to your local docker
$ sudo docker load -i <path to ubuntu1404_lappf.tar> <image name>
$ sudo docker images

Run behat tests on docker

Useful scripts

You can download two shell script files from [1]

  • run_mahara_container.sh helps you to run mahara container;
  • run_mahara_tests.sh is for running behat tests.

Run mahara container

$ run_mahara_container.sh <name of container> <port> <path to mahara code> <path to mahara dataroot> [<image name>]
  • Choose a <name of container> to identify the container in case you are running multiple mahara containers. The <name of container> will be also used for other commands(see below).
  • Choose a <port> to access the mahara site on the docker via web browser. After your docker container is succesfully launched, you can access the mahara site via the URL: http://localhost:<port>/.
  • <path to mahara code> is the path to your mahara code directory on the host machine. This must contain the 'htdocs' directory and must be readable by user www-data.
  • <path to mahara dataroot> is the path to store the mahara site data on the host machine. The cron.log file will be stored in this as well. This must be readable and writable by user www-data. Run the following command to create it
$ sudo -u www-data mkdir -p <path to mahara dataroot>
  • Update the <path to mahara code>/htdocs/config.php file with:
$cfg->wwwroot  = 'http://localhost:<port>/';
$cfg->dataroot = '/var/lib/sitedata';

The container has a PostgreSQL server running on it. You can use it with the following settings

$cfg->dbtype   = 'postgres8';
$cfg->dbhost   = 'localhost';
$cfg->dbuser   = 'maharauser';
$cfg->dbname   = 'mahara-db';
$cfg->dbpass   = 'mahara';

You can use the postgres server running on your host machine.

$cfg->dbhost   = '<your host machine IP address>';

You will see the text You can now access the mahara site at http://localhost:<port>/ if succeeded.

The script will generate css and install PHP Composer and required components if needed.

Stop a running mahara container

$ stop_mahara_container.sh <name of container>

Access the postgres db server on the container

$ sudo docker exec -it <name of container> sudo -u postgres psql mahara-db

Please note that the database on the docker container will be deleted when you stop the container

Run mahara behat tests

While the container running, you can run behat tests in another terminal.

Update behat settings in config.php

  • Create the 'behat' directory inside <path to mahara dataroot>, and make sure it is writable by www-data
$ sudo -u www-data mkdir <path to mahara dataroot>/behat
  • Update behat settings in <path to mahara code>/htdocs/config.php
$cfg->behat_dbprefix  = 'behat_';
$cfg->behat_wwwroot  = 'http://localhost/';
$cfg->behat_dataroot = '/var/lib/sitedata/behat';

Run tests

$ run_mahara_tests.sh <name of container> run|rundebug [@tag_name|<feature file>]