---
services: docker

env:
  - distro: centos7
    playbook: centos-7-test.yml
  - distro: centos6
    playbook: test.yml
  - distro: debian8
    playbook: test.yml
  - distro: ubuntu1604
    playbook: test.yml
  - distro: ubuntu1404
    playbook: test.yml

script:
  # Configure test script so we can run extra tests after playbook is run.
  - export container_id=$(date +%s)
  - export cleanup=false

  # Download test shim.
  - wget -O ${PWD}/tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/
  - chmod +x ${PWD}/tests/test.sh

  # Run tests.
  - ${PWD}/tests/test.sh

  # Some MySQL debugging (show all the logs).
  - docker exec --tty ${container_id} env TERM=xterm ls -lah /var/log
  - docker exec --tty ${container_id} env TERM=xterm cat /var/log/mysql/error.log || true
  - docker exec --tty ${container_id} env TERM=xterm cat /var/log/mysql.err || true

  # Check to make sure we can connect to MySQL via Unix socket.
  - >
    sudo docker exec ${container_id} mysql -u root -proot -e 'show databases;'
    | grep -q 'information_schema'
    && (echo 'MySQL running normally' && exit 0)
    || (echo 'MySQL not running' && exit 1)

  # Check to make sure we can connect to MySQL via TCP.
  - >
    sudo docker exec ${container_id} mysql -u root -proot -h 127.0.0.1 -e 'show databases;'
    | grep -q 'information_schema'
    && (echo 'MySQL running normally' && exit 0)
    || (echo 'MySQL not running' && exit 1)

after_failure:
  # Check MySQL settings.
  - 'docker exec --tty ${container_id} env TERM=xterm cat /var/log/mysql/error.log'
  - 'docker exec --tty ${container_id} env TERM=xterm cat /var/log/mysql.err'
  - 'docker exec --tty ${container_id} env TERM=xterm cat /var/log/mysql.log'

notifications:
  webhooks: https://galaxy.ansible.com/api/v1/notifications/
