ref(tests): Use common.sh on tests

This commit is contained in:
Carlos Álvaro
2021-11-04 19:48:55 +01:00
parent 73c617bb3d
commit c85cbbf000
4 changed files with 74 additions and 59 deletions

View File

@@ -3,35 +3,43 @@
set -e
[ "${DEBUG}" == true ] && set -vx
echo "🧪 Running gitfs tests ..."
# https://stackoverflow.com/a/4774063/3398062
SCRIPT_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
# shellcheck source=assets/build/functions.sh
COMMON_FILE="${SCRIPT_PATH}/../lib/common.sh"
source "${COMMON_FILE}"
echo "🧪 Running gitfs tests ..."
trap cleanup EXIT
export GITFS_KEYS_DIR=${GITFS_KEYS_DIR:-tests/gitfs/data/keys/gitfs}
# Check gitfs keys are present
echo "==> Checking gitfs keys are present ..."
if [[ ! -f "${GITFS_KEYS_DIR}/gitfs_ssh" || ! -f "${GITFS_KEYS_DIR}/gitfs_ssh.pub" ]]; then
error "gitfs keys not found at ${GITFS_KEYS_DIR}"
fi
ok "gitfs keys"
# Run test instance
echo "==> Starting docker-salt-master (${PLATFORM}) with RSA 4096 ssh key ..."
start_container_and_wait \
--volume "$(pwd)/tests/gitfs/config":/home/salt/data/config:ro \
--volume "$(pwd)/tests/gitfs/data/keys":/home/salt/data/keys \
--volume "$(pwd)/${GITFS_KEYS_DIR%%/gitfs}":/home/salt/data/keys \
|| error "container started"
ok "container started"
# Update repositories
echo "==> Updating gitfs repositories ..."
docker exec "${CONTAINER_NAME}" salt-run cache.clear_git_lock gitfs type=update
UPDATE_REPOS="$(docker exec "${CONTAINER_NAME}" salt-run fileserver.update)"
salt-run cache.clear_git_lock gitfs type=update
UPDATE_REPOS="$( salt-run fileserver.update )"
echo "${UPDATE_REPOS}" | grep -qi 'true' || error "update gitfs"
ok "update gitfs"
# Check pillars
echo "==> Checking gitfs files ..."
FILE_LIST=$(docker exec "${CONTAINER_NAME}" salt-run fileserver.file_list)
FILE_LIST=$( salt-run fileserver.file_list )
echo "${FILE_LIST}"
[[ "${FILE_LIST}" == *test.txt* ]] || error "gitfs files"
ok "gitfs files"