2017-02-04 17:46:12 +01:00
|
|
|
#!/bin/bash
|
|
|
|
# Run tests against Mattermost installation on a Vagrant virtual machine.
|
|
|
|
#
|
|
|
|
# The VM is provisioned with a fresh Yunohost install, then snapshotted
|
|
|
|
# for subsequent runs.
|
|
|
|
|
|
|
|
# Fail on first error
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# Configuration constants
|
|
|
|
APP_NAME="mattermost"
|
2017-10-12 14:34:51 +02:00
|
|
|
APP_DIR="/vagrant"
|
2017-10-23 10:59:18 +02:00
|
|
|
DOMAIN="ynhtests.local"
|
2017-02-04 17:46:12 +01:00
|
|
|
VM_ROOT_PASSWORD="alpine"
|
|
|
|
YUNOHOST_ADMIN_PASSWORD="alpine"
|
|
|
|
|
|
|
|
function _usage() {
|
|
|
|
echo "Run tests against ${APP_NAME} installation on a Vagrant virtual machine."
|
|
|
|
echo "Usage: test.sh [--skip-snapshot] [--verbose] [--help]"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Configuration arguments
|
|
|
|
function _parse_args() {
|
|
|
|
VERBOSE=false
|
|
|
|
VERBOSE_OPT=''
|
|
|
|
SKIP_SNAPSHOT=false
|
|
|
|
while [ "$1" != "" ]; do
|
|
|
|
case $1 in
|
|
|
|
"-v" | "--verbose")
|
|
|
|
shift
|
|
|
|
VERBOSE=true
|
|
|
|
VERBOSE_OPT='--verbose';;
|
|
|
|
"-s" | "--skip-snapshot")
|
|
|
|
shift
|
|
|
|
SKIP_SNAPSHOT=true;;
|
|
|
|
"--help")
|
|
|
|
_usage
|
|
|
|
exit;;
|
|
|
|
*)
|
|
|
|
_usage
|
|
|
|
exit 1;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# Execute an ssh command on the vagrant box
|
|
|
|
function _vagrant_ssh() {
|
|
|
|
local command="$1"
|
|
|
|
local tty_output=$([ $VERBOSE ] && echo '/dev/stdout' || echo '/dev/null')
|
|
|
|
|
|
|
|
[ $VERBOSE == true ] && echo "vagrant ssh -c \"$command\""
|
|
|
|
|
|
|
|
vagrant ssh -c "$command" \
|
|
|
|
> $tty_output \
|
|
|
|
2> >(grep --invert-match 'Connection to 127.0.0.1 closed.' 1>&2) # Filter out the SSH deconnection message printed on stderr
|
2017-10-11 12:03:37 +02:00
|
|
|
local exit_code=$?
|
|
|
|
return $exit_code
|
2017-02-04 17:46:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function _assert_success() {
|
|
|
|
local message="$1"
|
|
|
|
local command="$2"
|
2017-10-11 12:03:37 +02:00
|
|
|
if [ -z "$command" ]; then
|
|
|
|
echo "Invalid arguments: command missing."
|
|
|
|
echo "Usage: _assert_success <message> <command>"
|
|
|
|
return -1
|
|
|
|
fi
|
2017-02-04 17:46:12 +01:00
|
|
|
|
|
|
|
local RED=`tput setaf 1`
|
|
|
|
local GREEN=`tput setaf 2`
|
|
|
|
local BOLD=`tput bold`
|
|
|
|
local RESET=`tput sgr0`
|
|
|
|
|
|
|
|
set +e # Allow continuing the script on failures
|
|
|
|
if _vagrant_ssh "$command"; then
|
|
|
|
printf "[${GREEN}${BOLD}OK${RESET}] $message\n"
|
|
|
|
else
|
|
|
|
printf "[${RED}${BOLD}KO${RESET}] $message\n"
|
|
|
|
fi
|
|
|
|
set -e # Fail again on first error
|
|
|
|
}
|
|
|
|
|
2017-10-11 12:03:37 +02:00
|
|
|
function _assert_mattermost_frontpage_up() {
|
|
|
|
local domain="$1"
|
|
|
|
|
|
|
|
# On the default Yunohost Vagrant box, this file
|
|
|
|
# bypass all SSOWAT configurations, and redirects the root of the domain to the SSO login form.
|
|
|
|
# We need to access the frontpage, so we remove this bypass.
|
|
|
|
_vagrant_ssh "sudo rm -f /etc/ssowat/conf.json.persistent"
|
|
|
|
|
|
|
|
_assert_success \
|
|
|
|
"Mattermost frontpage is reachable" \
|
|
|
|
"curl --silent --show-error --insecure -L -H 'Host: ${DOMAIN}' --resolve ${DOMAIN}:443:127.0.0.1 https://${DOMAIN}/ | grep -q 'Mattermost'"
|
|
|
|
}
|
|
|
|
|
2017-02-04 17:46:12 +01:00
|
|
|
function setup() {
|
|
|
|
if $SKIP_SNAPSHOT; then
|
|
|
|
echo "--- Starting Vagrant box ---"
|
2017-09-12 11:35:04 +02:00
|
|
|
vagrant up --no-provision
|
2017-02-04 17:46:12 +01:00
|
|
|
echo "--- (Skipping snapshot restore) ---"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2017-09-11 11:14:53 +02:00
|
|
|
if (vagrant snapshot list | grep 'yunohost-jessie-pristine' > /dev/null); then
|
2017-02-04 17:46:12 +01:00
|
|
|
echo "--- Restoring Vagrant snapshot ---"
|
2017-10-12 07:01:22 +02:00
|
|
|
vagrant snapshot restore yunohost-jessie-pristine
|
2017-02-04 17:46:12 +01:00
|
|
|
else
|
|
|
|
echo "--- Provisioning Vagrant box ---"
|
|
|
|
vagrant up --provision
|
|
|
|
echo "--- Saving Vagrant snapshot ---"
|
2017-09-11 11:14:53 +02:00
|
|
|
vagrant snapshot save yunohost-jessie-pristine
|
2017-02-04 17:46:12 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_simple_install() {
|
|
|
|
echo "--- Running simple installation test ---"
|
2017-09-11 11:14:53 +02:00
|
|
|
_vagrant_ssh "sudo yunohost app install '$APP_DIR' --args 'domain=${DOMAIN}&public_site=Yes&analytics=0' $VERBOSE_OPT"
|
2017-10-11 12:03:37 +02:00
|
|
|
_assert_mattermost_frontpage_up "$DOMAIN"
|
2017-02-04 17:46:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_simple_upgrade() {
|
|
|
|
echo "--- Running simple upgrade test ---"
|
|
|
|
_vagrant_ssh "sudo yunohost app upgrade $APP_NAME --file '$APP_DIR' $VERBOSE_OPT"
|
2017-10-11 12:03:37 +02:00
|
|
|
_assert_mattermost_frontpage_up "$DOMAIN"
|
2017-02-04 17:46:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_simple_backup() {
|
|
|
|
echo "--- Running simple backup test ---"
|
2017-10-12 08:27:13 +02:00
|
|
|
_vagrant_ssh "sudo yunohost backup create --name mattermost-test-backup --ignore-system $VERBOSE_OPT --apps $APP_NAME"
|
2017-09-11 12:05:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_simple_remove() {
|
|
|
|
echo "--- Running simple remove test ---"
|
|
|
|
_vagrant_ssh "sudo yunohost app remove $APP_NAME"
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_simple_restore() {
|
|
|
|
echo "--- Running simple restore test ---"
|
2017-10-12 08:27:13 +02:00
|
|
|
_vagrant_ssh "sudo yunohost backup restore mattermost-test-backup --force --ignore-system $VERBOSE_OPT --apps $APP_NAME"
|
2017-10-11 12:03:37 +02:00
|
|
|
_assert_mattermost_frontpage_up "$DOMAIN"
|
2017-02-04 17:46:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_package_check() {
|
2017-09-11 12:14:49 +02:00
|
|
|
echo "--- Running package_check ---"
|
2017-10-23 16:06:40 +02:00
|
|
|
_vagrant_ssh "package_check/package_check.sh --build-lxc --bash-mode '$APP_DIR'"
|
2017-02-04 17:46:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function teardown() {
|
|
|
|
echo "--- Cleaning up ---"
|
|
|
|
}
|
|
|
|
|
|
|
|
_parse_args $*
|
|
|
|
setup
|
2017-10-23 16:06:40 +02:00
|
|
|
test_package_check
|
2017-02-04 17:46:12 +01:00
|
|
|
test_simple_install
|
2017-10-16 06:32:16 +02:00
|
|
|
test_simple_upgrade
|
|
|
|
test_simple_backup
|
|
|
|
test_simple_remove
|
|
|
|
test_simple_restore
|
2017-02-04 17:46:12 +01:00
|
|
|
teardown
|