docker-keepalived/test/test_helper.bash

76 lines
1.3 KiB
Bash
Raw Permalink Normal View History

2015-06-09 18:41:43 +00:00
setup() {
IMAGE_NAME="$NAME:$VERSION"
}
2015-07-17 07:23:24 +00:00
# function relative to the current container / image
2015-06-09 18:41:43 +00:00
build_image() {
#disable outputs
docker build -t $IMAGE_NAME $BATS_TEST_DIRNAME/../image &> /dev/null
}
run_image() {
CONTAINER_ID=$(docker run $@ -d $IMAGE_NAME)
CONTAINER_IP=$(get_container_ip_by_cid $CONTAINER_ID)
}
start_container() {
start_containers_by_cid $CONTAINER_ID
}
stop_container() {
stop_containers_by_cid $CONTAINER_ID
}
remove_container() {
remove_containers_by_cid $CONTAINER_ID
}
clear_container() {
stop_containers_by_cid $CONTAINER_ID
remove_containers_by_cid $CONTAINER_ID
}
2016-09-02 18:56:07 +00:00
wait_process() {
wait_process_by_cid $CONTAINER_ID $@
2015-06-09 18:41:43 +00:00
}
2015-07-17 07:23:24 +00:00
# generic functions
2015-06-09 18:41:43 +00:00
get_container_ip_by_cid() {
local IP=$(docker inspect -f "{{ .NetworkSettings.IPAddress }}" $1)
echo "$IP"
}
start_containers_by_cid() {
for cid in "$@"
do
#disable outputs
docker start $cid &> /dev/null
2015-07-17 07:23:24 +00:00
done
2015-06-09 18:41:43 +00:00
}
stop_containers_by_cid() {
for cid in "$@"
do
#disable outputs
docker stop $cid &> /dev/null
2015-07-17 07:23:24 +00:00
done
2015-06-09 18:41:43 +00:00
}
remove_containers_by_cid() {
for cid in "$@"
do
#disable outputs
docker rm $cid &> /dev/null
2015-07-17 07:23:24 +00:00
done
2015-06-09 18:41:43 +00:00
}
clear_containers_by_cid() {
stop_containers_by_cid $@
remove_containers_by_cid $@
}
2016-09-02 18:56:07 +00:00
wait_process_by_cid() {
2015-06-09 18:41:43 +00:00
cid=$1
2016-09-02 18:56:07 +00:00
docker exec $cid /container/tool/wait-process ${@:2}
2015-07-17 07:23:24 +00:00
}