awesome-compose/lib/test_helper.bash
Chad Metcalf 702ec96821
Adding a Makefile and basic tests.
This approach uses bats to create a generic docker-compose test. It
checks that images are pullable, projects are buildable, up works, and
if ports are exposed that something is listening.

The tests can be tailored for each example. As long as they are the same
though, you can edit lib/test.bats.example and then `make update-tests`
and all the tests will be synced.

Signed-off-by: Chad Metcalf <chad@docker.com>
2020-08-08 14:26:52 -07:00

29 lines
708 B
Bash

function docker_compose_project_name() {
echo "$(basename ${BATS_TEST_DIRNAME})"
}
# Runs docker ps -a filtered by the current project name
function docker_ps_by_project() {
docker ps -a \
--filter "label=com.docker.compose.project=$(docker_compose_project_name)" \
"${@}"
}
function check_deps() {
# external commands we depend on for testing
local dependancies=(nc)
for i in ${dependancies[@]}; do
if [ ! command -v ${i} &> /dev/null ]; then
echo "${i} could not be found"
exit
fi
done
}
function compose_cleanup() {
docker-compose kill || true
docker-compose rm --force -v || true
docker-compose down --volumes || true
}