Add tests for actions, containers and services actions

Tests should run fine now with macOS
This commit is contained in:
Tortue Torche 2021-09-14 10:53:59 +02:00
parent c54255381b
commit ead44c5ed5
5 changed files with 40 additions and 13 deletions

View File

@ -5,10 +5,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Added
- Add tests for `actions`, `containers` and `services` actions
### Changed
- Downgrade Docker Compose from [1.29.2](https://github.com/docker/compose/releases/tag/1.29.2) to [1.28.0](https://github.com/docker/compose/releases/tag/1.28.0) for Alpine image, to get faster builds 🚀
- Reduce Docker images size based on Alpine, again
### Fixed
- Tests should run fine now with macOS
## [1.2.0-beta.1] - 2021-09-03
### Added

View File

@ -5,10 +5,10 @@
# cd psu/
# cp tests/dockerfiles/.env.local tests/dockerfiles/.env
# source tests/dockerfiles/.env
# docker build --no-cache -t $PSU_IMAGE:$PSU_TAG -f Dockerfile .
# docker build --no-cache -t $PSU_IMAGE:core-$PSU_TAG -f Dockerfile.core .
# docker build --no-cache -t $PSU_IMAGE:debian-$PSU_TAG -f Dockerfile.debian .
# docker build --no-cache -t $PSU_IMAGE:debaian-core-$PSU_TAG -f Dockerfile.debian-core .
# docker build --no-cache -t ${PSU_IMAGE}:${PSU_TAG} -f Dockerfile .
# docker build --no-cache -t ${PSU_IMAGE}:core-${PSU_TAG} -f Dockerfile.core .
# docker build --no-cache -t ${PSU_IMAGE}:debian-${PSU_TAG} -f Dockerfile.debian .
# docker build --no-cache -t ${PSU_IMAGE}:debian-core-${PSU_TAG} -f Dockerfile.debian-core .
#
# Build Docker images from https://gitlab.com/psuapp/hub locally:
# cd ..
@ -49,9 +49,12 @@ PORTAINER_IMAGE="portainer/portainer-ce"
#PORTAINER_IMAGE="portainer/portainer"
PORTAINER_VERSION=latest
#PORTAINER_VERSION="2.6.3"
#PORTAINER_VERSION="1.24.1"
#PORTAINER_VERSION="1.24.2"
PORTAINER_COMMAND_OPTIONS=""
#PORTAINER_COMMAND_OPTIONS=" --no-analytics"
#PORTAINER_DEPLOY_EXTRA_ARGS="--debug --verbose"
SWARM_NODE_NAME=localhost
SWARM_NODE_IP=$(hostname -I | awk '{ print $1 }')
# For macOS
#SWARM_NODE_IP=$(ipconfig getifaddr en0)

View File

@ -46,5 +46,6 @@ networks:
secrets:
psu-portainer-password:
external: true
volumes:
psu-portainer:

View File

@ -66,6 +66,7 @@ services:
networks:
psu-traefik-net:
driver: overlay
external: true
volumes:

View File

@ -68,16 +68,19 @@ function version {
}
# Leave Docker Swarm, if already set
docker swarm leave --force && sleep 3 | true
(docker swarm leave --force && sleep 3) || true
# Remove admin password from Docker secrets, if already set
docker secret rm psu-portainer-password | true
docker secret rm psu-portainer-password || true
# Delete all stopped containers
docker rm -f $(docker ps -a -q) || true
# Remove portainer data, if already set
docker volume rm --force portainer_psu-portainer && sleep 2 | true
(docker volume rm --force portainer_psu-portainer && sleep 2) || true
# Remove web-app data, if already set
docker volume rm --force web-app_psu-php-runner && sleep 2 | true
(docker volume rm --force web-app_psu-php-runner && sleep 2) || true
# Init Docker Swarm
docker swarm init
@ -103,11 +106,12 @@ psu_wrapper --version | grep -E 'version v?[0-9]+\.[0-9]+\.[0-9]+'
# psu help test
# Check if 4 terms present in the help message are visible when running the command
[ "$(psu_wrapper --help | grep -E 'Usage|Arguments|Options|Available actions' | wc -l)" == "4" ]
[ "$(psu_wrapper --help | grep -E 'Usage|Arguments|Options|Available actions' | wc -l | tr -d ' ')" == "4" ]
# TODO: test 'actions' action
# TODO: test 'services' action
# TODO: test 'containers' action
# psu 'actions' action test
# Check if some of the available actions of psu
# are visible when running the 'actions' command
[ "$(psu_wrapper actions | grep -E ' deploy | rm | ls | status | services | tasks | actions ' | wc -l | tr -d ' ')" == "7" ]
# Portainer login test
PSU_AUTH_TOKEN=$(psu_wrapper login --user $PSU_USER --password $PSU_PASSWORD --url $PSU_URL --insecure)
@ -159,6 +163,19 @@ stack_envvars="$(echo -n "$stack_info" | jq ".Env" -jc)"
stack_list="$(psu_wrapper ls --user $PSU_USER --password $PSU_PASSWORD --url $PSU_URL --insecure --debug false --verbose false --quiet)"
[ "$stack_list" == "$PSU_STACK_NAME" ]
# psu 'services' action test
# The current stack should have 3 services:
# 'web-app_app', 'web-app_job' and 'web-app_web'
[ "$(psu_wrapper services --user=$PSU_USER --password=$PSU_PASSWORD --url=$PSU_URL --name=$PSU_STACK_NAME --insecure --debug false --verbose false --quiet | wc -l | tr -d ' ')" == "3" ]
# psu 'tasks:healthy' action test
# The current stack should have 3 healthy tasks:
[ "$(psu_wrapper tasks:healthy --user=$PSU_USER --password=$PSU_PASSWORD --url=$PSU_URL --name=$PSU_STACK_NAME --insecure --debug false --verbose false --quiet | wc -l | tr -d ' ')" == "3" ]
# psu 'containers' action test
# The current stack should have 2 running containers:
[ "$(psu_wrapper containers --user=$PSU_USER --password=$PSU_PASSWORD --url=$PSU_URL --name=$PSU_STACK_NAME --insecure --debug false --verbose false --quiet | wc -l | tr -d ' ')" == "2" ]
# Convert env file in a base64 encoded string,
# due to some limitations with Docker in Docker and volumes
# see: https://stackoverflow.com/a/55481515