mirror of https://github.com/docker/docs.git
Merge pull request #448 from aluzzardi/integration
Integration tests: Initial framework
This commit is contained in:
commit
d708650670
|
|
@ -0,0 +1,16 @@
|
||||||
|
#!/usr/bin/env bats
|
||||||
|
|
||||||
|
load helpers
|
||||||
|
|
||||||
|
function teardown() {
|
||||||
|
stop_manager
|
||||||
|
stop_docker
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "docker info should return the number of nodes" {
|
||||||
|
start_docker 3
|
||||||
|
start_manager
|
||||||
|
run docker_swarm info
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[ "${lines[1]}"="Nodes: 3" ]
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,80 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Root directory of the repository.
|
||||||
|
SWARM_ROOT=${BATS_TEST_DIRNAME}/../..
|
||||||
|
|
||||||
|
# Docker image and version to use for integration tests.
|
||||||
|
DOCKER_IMAGE=${DOCKER_IMAGE:-aluzzardi/docker}
|
||||||
|
DOCKER_VERSION=${DOCKER_VERSION:-1.5}
|
||||||
|
|
||||||
|
# Host on which the manager will listen to (random port between 6000 and 7000).
|
||||||
|
SWARM_HOST=127.0.0.1:$(( ( RANDOM % 1000 ) + 6000 ))
|
||||||
|
|
||||||
|
# Use a random base port (for engines) between 5000 and 6000.
|
||||||
|
BASE_PORT=$(( ( RANDOM % 1000 ) + 5000 ))
|
||||||
|
|
||||||
|
# Join an array with a given separator.
|
||||||
|
function join() {
|
||||||
|
local IFS="$1"
|
||||||
|
shift
|
||||||
|
echo "$*"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Run the swarm binary.
|
||||||
|
function swarm() {
|
||||||
|
${SWARM_ROOT}/swarm "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Waits until the given docker engine API becomes reachable.
|
||||||
|
function wait_until_reachable() {
|
||||||
|
local attempts=0
|
||||||
|
until docker -H $1 info &> /dev/null || [ $attempts -ge 10 ]; do
|
||||||
|
echo "Attempt to connect to ${HOSTS[$i]} failed for the $((++attempts)) time" >&2
|
||||||
|
sleep 0.5
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# Start the swarm manager in background.
|
||||||
|
function start_manager() {
|
||||||
|
${SWARM_ROOT}/swarm manage -H $SWARM_HOST "$@" `join , ${HOSTS[@]}` &
|
||||||
|
SWARM_PID=$!
|
||||||
|
wait_until_reachable $SWARM_HOST
|
||||||
|
}
|
||||||
|
|
||||||
|
# Stops the manager.
|
||||||
|
function stop_manager() {
|
||||||
|
kill $SWARM_PID
|
||||||
|
}
|
||||||
|
|
||||||
|
# Run the docker CLI against swarm.
|
||||||
|
function docker_swarm() {
|
||||||
|
docker -H $SWARM_HOST "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Start N docker engines.
|
||||||
|
function start_docker() {
|
||||||
|
local current=${#DOCKER_CONTAINERS[@]}
|
||||||
|
local instances="$1"
|
||||||
|
shift
|
||||||
|
local i
|
||||||
|
|
||||||
|
# Start the engines.
|
||||||
|
for ((i=current; i < (current + instances); i++)); do
|
||||||
|
local port=$(($BASE_PORT + $i))
|
||||||
|
HOSTS[$i]=127.0.0.1:$port
|
||||||
|
DOCKER_CONTAINERS[$i]=$(docker run -d --name node-$i -h node-$i --privileged -p 127.0.0.1:$port:$port -it ${DOCKER_IMAGE}:${DOCKER_VERSION} docker -d -H 0.0.0.0:$port "$@")
|
||||||
|
done
|
||||||
|
|
||||||
|
# Wait for the engines to be reachable.
|
||||||
|
for ((i=current; i < (current + instances); i++)); do
|
||||||
|
wait_until_reachable ${HOSTS[$i]}
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# Stop all engines.
|
||||||
|
function stop_docker() {
|
||||||
|
for id in ${DOCKER_CONTAINERS[@]}; do
|
||||||
|
echo "Stopping $id"
|
||||||
|
docker rm -f -v $id > /dev/null;
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
#!/usr/bin/env bats
|
|
||||||
|
|
||||||
load vars
|
|
||||||
|
|
||||||
@test "managing non-available node should be timed out" {
|
|
||||||
|
|
||||||
#
|
|
||||||
# timeout does not accept a bash function, so hard-coded path is required
|
|
||||||
#
|
|
||||||
run timeout 15s $GOBIN/swarm manage -H 127.0.0.1:2375 nodes://8.8.8.8:2375
|
|
||||||
|
|
||||||
[ "$status" -ne 0 ]
|
|
||||||
[[ ${lines[0]} =~ "Listening for HTTP" ]]
|
|
||||||
[[ ${lines[1]} =~ "ConnectEx tcp: i/o timeout" ]]
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
function swarm() {
|
|
||||||
$GOBIN/swarm $@
|
|
||||||
}
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
#!/usr/bin/env bats
|
#!/usr/bin/env bats
|
||||||
|
|
||||||
load vars
|
load helpers
|
||||||
|
|
||||||
@test "version string should contain a proper number with git commit" {
|
@test "version string should contain a proper number with git commit" {
|
||||||
run swarm -v
|
run swarm -v
|
||||||
|
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
[[ ${lines[0]} =~ version\ [0-9]+\.[0-9]+\.[0-9]+\ \([0-9a-f]{7}\)$ ]]
|
[[ ${lines[0]} =~ version\ [0-9]+\.[0-9]+\.[0-9]+ ]]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue