From f83b3daabbf8d2be500378ecaa4aaff5003b0397 Mon Sep 17 00:00:00 2001 From: Xian Chaobo Date: Wed, 22 Apr 2015 06:16:12 +0800 Subject: [PATCH] add events-search-stats-version-wait integration test Signed-off-by: Xian Chaobo --- test/integration/api.bats | 108 ++++++++++++++++++++++++++++++++++---- 1 file changed, 98 insertions(+), 10 deletions(-) diff --git a/test/integration/api.bats b/test/integration/api.bats index 8d16247f8f..6c2d91faaf 100644 --- a/test/integration/api.bats +++ b/test/integration/api.bats @@ -182,9 +182,29 @@ function teardown() { [[ "${lines[*]}" == *"diff.txt"* ]] } -# FIXME @test "docker events" { - skip + TEMP_FILE=$(mktemp) + start_docker 3 + swarm_manage + + # start events, report real time events to TEMP_FILE + docker_swarm events > $TEMP_FILE & + + # events: create container + run docker_swarm create --name test_container busybox sleep 100 + [ "$status" -eq 0 ] + # events: start container + run docker_swarm start test_container + [ "$status" -eq 0 ] + + # make sure $TEMP_FILE exists and is not empty + [ -s $TEMP_FILE ] + + # verify + run cat $TEMP_FILE + [ "$status" -eq 0 ] + [[ "${output}" == *"create"* ]] + [[ "${output}" == *"start"* ]] } @test "docker exec" { @@ -748,9 +768,27 @@ function teardown() { rm -f $temp_file_name_o } -# FIXME @test "docker search" { - skip + start_docker 3 + swarm_manage + + TEMP_NAME=noimage$RANDOM + # search image (not exist), the name of images only [a-z0-9-_.] are allowed + run docker_swarm search $TEMP_NAME + [ "$status" -eq 0 ] + [ "${#lines[@]}" -eq 1 ] + [[ "${lines[0]}" == *"DESCRIPTION"* ]] + + # search busybox (image exist) + run docker_swarm search busybox + [ "$status" -eq 0 ] + + # search existed image, output: latest + header at least + [ "${#lines[@]}" -ge 2 ] + # Every line should contain "busybox" exclude the first head line + for((i=1; i<${#lines[@]}; i++)); do + [[ "${lines[i]}" == *"busybox"* ]] + done } @test "docker start" { @@ -775,9 +813,32 @@ function teardown() { [[ "${lines[1]}" == *"Up"* ]] } -# FIXME @test "docker stats" { - skip + TEMP_FILE=$(mktemp) + start_docker 3 + swarm_manage + # stats running container + run docker_swarm run -d --name test_container busybox sleep 50 + [ "$status" -eq 0 ] + + # make sure container is up + run docker_swarm ps -l + [ "${#lines[@]}" -eq 2 ] + [[ "${lines[1]}" == *"test_container"* ]] + [[ "${lines[1]}" == *"Up"* ]] + + # storage the real time output of stats in TEMP_FILE + docker_swarm stats test_container > $TEMP_FILE & + + # make sure TEMP_FILE exists and is not empty + sleep 3 + [ -s $TEMP_FILE ] + + # if "CPU %" in TEMP_FILE, status is 0 + run grep "CPU %" $TEMP_FILE + [ "$status" -eq 0 ] + run grep "MEM USAGE/LIMIT" $TEMP_FILE + [ "$status" -eq 0 ] } @test "docker stop" { @@ -880,12 +941,39 @@ function teardown() { [[ "${lines[1]}" != *"Paused"* ]] } -# FIXME @test "docker version" { - skip + start_docker 3 + swarm_manage + + # version + run docker_swarm version + [ "$status" -eq 0 ] + [ "${#lines[@]}" -ge 8 ] + + # verify + client_reg='^Client version: [0-9]+\.[0-9]+\.[0-9]+$' + server_reg='^Server version: swarm/[0-9]+\.[0-9]+\.[0-9]+$' + [[ "${lines[0]}" =~ $client_reg ]] + [[ "${lines[5]}" =~ $server_reg ]] } -# FIXME @test "docker wait" { - skip + start_docker 3 + swarm_manage + + # run after 10 seconds, test_container will exit + run docker_swarm run -d --name test_container busybox sleep 10 + [ "$status" -eq 0 ] + + # make sure container exists and is up + run docker_swarm ps -l + [ "${#lines[@]}" -eq 2 ] + [[ "${lines[1]}" == *"test_container"* ]] + [[ "${lines[1]}" == *"Up"* ]] + + # wait until exist(after 10 seconds) + run docker_swarm wait test_container + [ "$status" -eq 0 ] + [ "${#lines[@]}" -eq 1 ] + [[ "${lines[0]}" == "0" ]] }