mirror of
https://github.com/YunoHost-Apps/mattermost_ynh.git
synced 2024-09-03 19:36:29 +02:00
Add test.sh: run tests in a Vagrant box
For now the script setups a Vagrant box, and runs a simple installlation test. In the future it will also be able to run the package_test suite.
This commit is contained in:
parent
9f48b7393b
commit
11dfb6b884
3 changed files with 211 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
.vagrant
|
||||
|
75
Vagrantfile
vendored
Normal file
75
Vagrantfile
vendored
Normal file
|
@ -0,0 +1,75 @@
|
|||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
|
||||
# All Vagrant configuration is done below. The "2" in Vagrant.configure
|
||||
# configures the configuration version (we support older styles for
|
||||
# backwards compatibility). Please don't change it unless you know what
|
||||
# you're doing.
|
||||
Vagrant.configure("2") do |config|
|
||||
# The most common configuration options are documented and commented below.
|
||||
# For a complete reference, please see the online documentation at
|
||||
# https://docs.vagrantup.com.
|
||||
|
||||
config.vm.define :mattermost_ynh
|
||||
config.vm.box = "debian/contrib-jessie64"
|
||||
|
||||
# Disable auto updates checks. Run `vagrant outdated` to perform manual updates.
|
||||
config.vm.box_check_update = false
|
||||
|
||||
# Create a forwarded port mapping which allows access to a specific port
|
||||
# within the machine from a port on the host machine. In the example below,
|
||||
# accessing "localhost:8080" will access port 80 on the guest machine.
|
||||
# config.vm.network "forwarded_port", guest: 80, host: 8080
|
||||
# config.vm.network "forwarded_port", guest: 443, host: 8443
|
||||
|
||||
# Create a private network, which allows host-only access to the machine
|
||||
# using a specific IP.
|
||||
config.vm.network "private_network", ip: "192.168.33.10"
|
||||
|
||||
# Share an additional folder to the guest VM. The first argument is
|
||||
# the path on the host to the actual folder. The second argument is
|
||||
# the path on the guest to mount the folder. And the optional third
|
||||
# argument is a set of non-required options.
|
||||
config.vm.synced_folder "./", "/vagrant"
|
||||
|
||||
# Enable provisioning with a shell script. Additional provisioners such as
|
||||
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
|
||||
# documentation for more information about their specific syntax and use.
|
||||
config.vm.provision "shell", privileged: false, keep_color: true, inline: <<-SHELL
|
||||
TESTS_DIR="/home/vagrant/tests"
|
||||
APP_DIR="$TESTS_DIR/mattermost_ynh"
|
||||
VM_ROOT_PASSWORD="alpine"
|
||||
YUNOHOST_ADMIN_PASSWORD="alpine"
|
||||
|
||||
# Stop on first error
|
||||
set -e
|
||||
|
||||
# Upgrade the system packages
|
||||
#DEBIAN_FRONTEND=noninteractive sudo apt-get update
|
||||
#DEBIAN_FRONTEND=noninteractive sudo apt-get upgrade --yes -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold'
|
||||
|
||||
# Install git
|
||||
hash git 2>/dev/null || sudo apt-get install git --yes
|
||||
|
||||
# Install Yunohost
|
||||
if ! hash yunohost 2>/dev/null; then
|
||||
git clone https://github.com/YunoHost/install_script /tmp/install_script
|
||||
yes ${VM_ROOT_PASSWORD} | sudo passwd
|
||||
cd /tmp/install_script
|
||||
echo "Running Yunohost install script…"
|
||||
sudo ./install_yunohost -a
|
||||
sudo yunohost tools postinstall --domain mattermost-ynh.local --password ${YUNOHOST_ADMIN_PASSWORD}
|
||||
fi
|
||||
|
||||
# Install lxc
|
||||
if ! hash lxc-start 2>/dev/null; then
|
||||
DEBIAN_FRONTEND=noninteractive sudo apt-get update
|
||||
DEBIAN_FRONTEND=noninteractive sudo apt-get install --yes --fix-missing lxc
|
||||
fi
|
||||
|
||||
# Install package_check
|
||||
if ! [ -f "$HOME/package_check/package_check.sh" ]; then
|
||||
git clone https://github.com/YunoHost/package_check
|
||||
fi
|
||||
SHELL
|
||||
end
|
134
test.sh
Executable file
134
test.sh
Executable file
|
@ -0,0 +1,134 @@
|
|||
#!/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"
|
||||
TESTS_DIR="/home/vagrant/tests"
|
||||
APP_DIR="$TESTS_DIR/mattermost_ynh"
|
||||
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
|
||||
}
|
||||
|
||||
function _assert_success() {
|
||||
local message="$1"
|
||||
local command="$2"
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
function setup() {
|
||||
if $SKIP_SNAPSHOT; then
|
||||
echo "--- Starting Vagrant box ---"
|
||||
vagrant up
|
||||
echo "--- (Skipping snapshot restore) ---"
|
||||
return
|
||||
fi
|
||||
|
||||
if (vagrant snapshot list | grep 'yunohost-2.4-pristine' > /dev/null); then
|
||||
echo "--- Restoring Vagrant snapshot ---"
|
||||
vagrant snapshot restore yunohost-2.4-pristine
|
||||
else
|
||||
echo "--- Provisioning Vagrant box ---"
|
||||
vagrant up --provision
|
||||
echo "--- Saving Vagrant snapshot ---"
|
||||
vagrant snapshot save yunohost-2.4-pristine
|
||||
fi
|
||||
|
||||
echo "--- Copying app content into the box ---"
|
||||
if ! [ -d "$APP_DIR" ]; then
|
||||
_vagrant_ssh "mkdir -p '$TESTS_DIR'"
|
||||
_vagrant_ssh "cp -R '/vagrant' '$APP_DIR'"
|
||||
fi
|
||||
}
|
||||
|
||||
function test_simple_install() {
|
||||
echo "--- Running simple installation test ---"
|
||||
_vagrant_ssh "sudo yunohost app install '$APP_DIR' --args 'domain=mattermost-ynh.local&public_site=Yes&analytics=0' $VERBOSE_OPT"
|
||||
}
|
||||
|
||||
function test_simple_upgrade() {
|
||||
echo "--- Running simple upgrade test ---"
|
||||
_vagrant_ssh "sudo yunohost app upgrade $APP_NAME --file '$APP_DIR' $VERBOSE_OPT"
|
||||
}
|
||||
|
||||
function test_simple_backup() {
|
||||
echo "--- Running simple backup test ---"
|
||||
local BACKUP_DIR="$TESTS_DIR/backups"
|
||||
_vagrant_ssh "sudo yunohost backup create --ignore-hooks --no-compress --apps $APP_NAME --output-directory $BACKUP_DIR $VERBOSE_OPT"
|
||||
}
|
||||
|
||||
function test_package_check() {
|
||||
#echo "--- Running package_check ---"
|
||||
#_vagrant_ssh "package_check/package_check.sh --bash-mode '$APP_DIR'"
|
||||
echo "--- Skipping package_check ---"
|
||||
echo "(Our custom Vagrant box is not able to run LXC containers yet)"
|
||||
}
|
||||
|
||||
function teardown() {
|
||||
echo "--- Cleaning up ---"
|
||||
}
|
||||
|
||||
_parse_args $*
|
||||
setup
|
||||
test_simple_install
|
||||
test_simple_upgrade
|
||||
test_simple_backup
|
||||
test_package_check
|
||||
teardown
|
Loading…
Reference in a new issue