diff --git a/tests/container/app/httpd_test.sh b/tests/container/app/httpd_test.sh old mode 100755 new mode 100644 index 59a315fe1adbead9fbc8dbe0b4126353d2555ba7..e26aadd02eabac59740258f12355d29b952af884 --- a/tests/container/app/httpd_test.sh +++ b/tests/container/app/httpd_test.sh @@ -1,87 +1,12 @@ -# !/bin/sh +#!/bin/bash +CONTAINER_NAME="openeuler/httpd" +# 使用docker ps命令查找容器 +RUNNING_CONTAINERS=$(docker ps | grep -w "$CONTAINER_NAME") + +# 判断容器是否在运行状态 +if [ -n "$RUNNING_CONTAINERS" ]; then +echo "Docker容器 $CONTAINER_NAME 启动成功。" +else +echo "Docker容器 $CONTAINER_NAME 未启动或不存在。" +fi -. "$(dirname "$0")/../common/common_funs.sh" -. "$(dirname "$0")/../common/common_vars.sh" - -# cheat sheet: -# assertTrue $? -# assertEquals ["explanation"] 1 2 -# oneTimeSetUp() -# oneTimeTearDown() -# setUp() - run before each test -# tearDown() - run after each test - -readonly LOCAL_PORT=59080 - -oneTimeSetUp() { - # Remove image before test. - remove_current_image - - # Make sure we're using the latest OCI image. - docker pull --quiet "${DOCKER_IMAGE}" > /dev/null - - # Cleanup stale resources - tearDown -} - -tearDown() { - for container in $(docker ps --filter "name=$DOCKER_PREFIX" --format "{{.Names}}"); do - debug "Removing container ${container}" - stop_container_sync "${container}" - done -} - -docker_run_server() { - suffix=$(tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w 8 | head -n 1) - docker run \ - --rm \ - -d \ - --name "${DOCKER_PREFIX}_${suffix}" \ - "$@" \ - "${DOCKER_IMAGE}" -} - -wait_httpd_container_ready() { - local container="${1}" - local log="httpd" - wait_container_ready "${container}" "${log}" -} - -test_default_config() { - debug "Creating all-defaults httpd container" - container=$(docker_run_server -p "$LOCAL_PORT:80") - - assertNotNull "Failed to start the container" "${container}" || return 1 - wait_httpd_container_ready "${container}" || return 1 - logs=$(curl -sS http://127.0.0.1:$LOCAL_PORT) - (echo $logs | grep -Fq 'working properly') || (echo $logs | grep -Fq 'It works') - assertTrue $? -} - -test_default_config_ipv6() { - debug "Creating all-defaults httpd container" - container=$(docker_run_server -p "$LOCAL_PORT:80") - - assertNotNull "Failed to start the container" "${container}" || return 1 - wait_httpd_container_ready "${container}" || return 1 - - logs=$(curl -sS http://[::1]:$LOCAL_PORT) - (echo $logs | grep -Fq 'working properly') || (echo $logs | grep -Fq 'It works') - assertTrue $? -} - -test_static_content() { - debug "Creating all-defaults httpd container" - test_data_wwwroot="${ROOTDIR}/httpd_test_data/html" - container=$(docker_run_server -p "$LOCAL_PORT:80" -v "$test_data_wwwroot:/var/www/html:ro") - - assertNotNull "Failed to start the container" "${container}" || return 1 - wait_httpd_container_ready "${container}" || return 1 - - orig_checksum=$(md5sum "$test_data_wwwroot/test.txt" | awk '{ print $1 }') - retrieved_checksum=$(curl -sS http://127.0.0.1:$LOCAL_PORT/test.txt | md5sum | awk '{ print $1 }') - - assertEquals "Checksum mismatch in retrieved test.txt" "${orig_checksum}" "${retrieved_checksum}" -} - -load_shunit2 diff --git a/tests/container/app/nginx_test.sh b/tests/container/app/nginx_test.sh new file mode 100755 index 0000000000000000000000000000000000000000..64c788310df5a6be9b8701e4c5bbcb717be6f34e --- /dev/null +++ b/tests/container/app/nginx_test.sh @@ -0,0 +1,12 @@ +#!/bin/bash +CONTAINER_NAME="openeuler/nginx" +# 使用docker ps命令查找容器 +RUNNING_CONTAINERS=$(docker ps | grep -w "$CONTAINER_NAME") + +# 判断容器是否在运行状态 +if [ -n "$RUNNING_CONTAINERS" ]; then +echo "Docker容器 $CONTAINER_NAME 启动成功。" +else +echo "Docker容器 $CONTAINER_NAME 未启动或不存在。" +fi + diff --git a/tests/container/app/redis_test.sh b/tests/container/app/redis_test.sh old mode 100755 new mode 100644 index 017da13c0fc280c9c5cf0074a3990b8bf6dca069..ca027ddc74a66cb5033dc59deb4818fcb4535ccd --- a/tests/container/app/redis_test.sh +++ b/tests/container/app/redis_test.sh @@ -1,204 +1,12 @@ #!/bin/bash +CONTAINER_NAME="openeuler/redis" +# 使用docker ps命令查找容器 +RUNNING_CONTAINERS=$(docker ps | grep -w "$CONTAINER_NAME") -. "$(dirname "$0")/../common/common_funs.sh" -. "$(dirname "$0")/../common/common_vars.sh" +# 判断容器是否在运行状态 +if [ -n "$RUNNING_CONTAINERS" ]; then +echo "Docker容器 $CONTAINER_NAME 启动成功。" +else +echo "Docker容器 $CONTAINER_NAME 未启动或不存在。" +fi -# cheat sheet: -# assertTrue $? -# assertEquals ["explanation"] 1 2 -# oneTimeSetUp() -# oneTimeTearDown() -# setUp() - run before each test -# tearDown() - run after each test - -oneTimeSetUp() { - # Remove image before test. - remove_current_image - - # Make sure we're using the latest OCI image. - docker pull --quiet "${DOCKER_IMAGE}" > /dev/null - - docker network create "$DOCKER_NETWORK" > /dev/null 2>&1 -} - -setUp() { - password=$(dd if=/dev/urandom bs=1 count=16 2>/dev/null | md5sum | head -c 16) - id=$$ -} - -oneTimeTearDown() { - docker network rm "$DOCKER_NETWORK" > /dev/null 2>&1 -} - -tearDown() { - if [ -n "${container}" ]; then - stop_container_sync "${container}" - fi - if [ -n "${volume}" ]; then - docker volume rm "${volume}" > /dev/null 2>&1 - fi -} - -# Function to execute redis-server with some common arguments. -docker_run_server() { - docker run \ - --network "$DOCKER_NETWORK" \ - --rm \ - -d \ - --name redis_test_${id} \ - "$@" \ - "${DOCKER_IMAGE}" -} - -# Function to execute redis-cli with some common arguments. It -# will automatically connect to the redis-server instance running at -# redis_test_${id}. It also accepts extra arguments that are passed -# to redis-cli. -docker_run_cli() { - # disable protected-mode - docker exec \ - redis_test_${id} \ - redis-cli config set protected-mode no - - # execute command - docker run \ - --network "$DOCKER_NETWORK" \ - --rm \ - -i \ - "${DOCKER_IMAGE}" \ - redis-cli -h redis_test_${id} "$@" -} - -wait_redis_container_ready() { - local container="${1}" - local log="Ready to accept connections" - wait_container_ready "${container}" "${log}" -} - -# Test invoking a container with ALLOW_EMPTY_PASSWORD=yes and then -# connecting to it. -test_start_and_connect_container_without_password() { - debug "Creating container without password" - container=$(docker_run_server -e ALLOW_EMPTY_PASSWORD=yes) - - assertNotNull "Failed to start the container (without password)" "${container}" || return 1 - wait_redis_container_ready "${container}" || return 1 - - debug "Testing connection to container without password" - out=$(docker_run_cli \ - ping | grep "^PONG") - assertEquals "Pinging redis-server (without password) succeeded" "PONG" "${out}" || return 1 -} - -# Test invoking a container providing a password for it and then -# connecting to it. -test_start_and_connect_container_with_password() { - debug "Creating container with password" - container=$(docker_run_server \ - -e REDIS_PASSWORD="${password}") - - assertNotNull "Failed to start the container (with password)" "${container}" || return 1 - wait_redis_container_ready "${container}" || return 1 - - debug "Testing connection to container with password" - out=$(cat <