#!/bin/sh

set -e

cleanup () {
    retval=$?
    set +e
    if [ -n "${AUTOPKGTEST_ARTIFACTS}" ]; then
        for f in /etc/memcached.conf /var/log/memcached.log /var/log/puppet-apply.log; do
            [ -f "$f" ] &&  cp "$f" "$AUTOPKGTEST_ARTIFACTS"
        done
        if [ -d /run/systemd/system ]; then
            journalctl -u memcached.service > "${AUTOPKGTEST_ARTIFACTS}/memcached.service.log"
            journalctl -u memcached@11222.service > "${AUTOPKGTEST_ARTIFACTS}/memcached@11222.service.log"
        fi
    fi
    return $retval
}

trap cleanup EXIT

export MEMCACHED_SERVERS="127.0.0.1:11211"

cd debian/tests
rspec --format documentation spec/*_spec.rb
