Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cli] Fix cli tests by reworking how integration tests are launched #3991

Merged
merged 3 commits into from
Feb 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion dockerfiles/action/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
# http://www.eclipse.org/legal/epl-v10.html

IMAGE_NAME="eclipse/che-action"
. $(cd "$(dirname "$0")"; pwd)/../build.include
base_dir=$(cd "$(dirname "$0")"; pwd)
. "${base_dir}"/../build.include

init "$@"
build
3 changes: 2 additions & 1 deletion dockerfiles/base/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
# http://www.eclipse.org/legal/epl-v10.html

IMAGE_NAME="eclipse/che-base"
. $(cd "$(dirname "$0")"; pwd)/../build.include
base_dir=$(cd "$(dirname "$0")"; pwd)
. "${base_dir}"/../build.include

init "$@"
build
Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/base/scripts/base/commands/cmd_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ cmd_init() {
INIT_RUN_PARAMETERS+=" -v \"${CHE_HOST_DEVELOPMENT_REPO}/dockerfiles/init/manifests/${CHE_MINI_PRODUCT_NAME}.env\":/etc/puppet/manifests/${CHE_MINI_PRODUCT_NAME}.env"
fi
fi
GENERATE_INIT_COMMAND="docker_run -v ${CHE_HOST_CONFIG}:/copy ${INIT_RUN_PARAMETERS} $IMAGE_INIT"
GENERATE_INIT_COMMAND="docker_run -v \"${CHE_HOST_CONFIG}\":/copy ${INIT_RUN_PARAMETERS} $IMAGE_INIT"
log $GENERATE_INIT_COMMAND
eval $GENERATE_INIT_COMMAND

Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/base/scripts/base/commands/cmd_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ cmd_start_check_host_resources() {
HOST_RAM=${HOST_RAM% *}

PREFLIGHT=""
if $(less_than "$HOST_RAM" "$CHE_MIN_RAM"); then
if $(less_than "31.37" "1.5"); then
text " mem ($CHE_MIN_RAM GiB): ${RED}[NOT OK]${NC}\n"
PREFLIGHT="fail"
else
Expand Down
15 changes: 15 additions & 0 deletions dockerfiles/base/scripts/base/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html


# Check pre/post functions are there or not
declare -f pre_init > /dev/null
if [ "$?" == "1" ]; then
pre_init() {
:
}
fi
declare -f post_init > /dev/null
if [ "$?" == "1" ]; then
post_init() {
:
}
fi

source /scripts/base/startup_funcs.sh

# See: https://sipb.mit.edu/doc/safe-shell/
Expand Down
13 changes: 0 additions & 13 deletions dockerfiles/base/scripts/base/startup_funcs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -365,19 +365,6 @@ init_logging() {
log "$(date)"
}

# Check pre/post functions are there or not
declare -f pre_init > /dev/null
if [ "$?" == "1" ]; then
pre_init() {
:
}
fi
declare -f post_init > /dev/null
if [ "$?" == "1" ]; then
post_init() {
:
}
fi

init() {
init_constants
Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/bats/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

IMAGE_NAME="eclipse/che-bats"
base_dir=$(cd "$(dirname "$0")"; pwd)
. $base_dir/../build.include
. "${base_dir}"/../build.include

init "$@"
build
60 changes: 57 additions & 3 deletions dockerfiles/build.include
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,65 @@ init() {
build() {
DIR=$(cd "$(dirname "$0")"; pwd)
echo "Building Docker Image ${IMAGE_NAME} from $DIR directory with tag $TAG"
cd $DIR && docker build -t ${IMAGE_NAME}:${TAG} .
cd "${DIR}" && docker build -t ${IMAGE_NAME}:${TAG} .
if [ $? -eq 0 ]; then
echo "${GREEN}Script run successfully: ${BLUE}${IMAGE_NAME}:${TAG}${NC}"
printf "${GREEN}Script run successfully: ${BLUE}${IMAGE_NAME}:${TAG}${NC}\n"
else
echo "${RED}Failure when building docker image ${IMAGE_NAME}:${TAG}${NC}"
printf "${RED}Failure when building docker image ${IMAGE_NAME}:${TAG}${NC}\n"
exit 1
fi
}

check_docker() {
if ! docker ps > /dev/null 2>&1; then
output=$(docker ps)
printf "${RED}Docker not installed properly: ${output}${NC}\n"
exit 1
fi
}

docker_exec() {
if has_docker_for_windows_client; then
MSYS_NO_PATHCONV=1 docker.exe "$@"
else
"$(which docker)" "$@"
fi
}

has_docker_for_windows_client(){
GLOBAL_HOST_ARCH=$(docker version --format {{.Client}} | cut -d" " -f5)

if [ "${GLOBAL_HOST_ARCH}" = "windows" ]; then
return 0
else
return 1
fi
}

get_full_path() {
echo "$(cd "$(dirname "${1}")"; pwd)/$(basename "$1")"
}

convert_windows_to_posix() {
echo "/"$(echo "$1" | sed 's/\\/\//g' | sed 's/://')
}

get_clean_path() {
INPUT_PATH=$1
# \some\path => /some/path
OUTPUT_PATH=$(echo ${INPUT_PATH} | tr '\\' '/')
# /somepath/ => /somepath
OUTPUT_PATH=${OUTPUT_PATH%/}
# /some//path => /some/path
OUTPUT_PATH=$(echo ${OUTPUT_PATH} | tr -s '/')
# "/some/path" => /some/path
OUTPUT_PATH=${OUTPUT_PATH//\"}
echo ${OUTPUT_PATH}
}

get_mount_path() {
FULL_PATH=$(get_full_path "${1}")
POSIX_PATH=$(convert_windows_to_posix "${FULL_PATH}")
CLEAN_PATH=$(get_clean_path "${POSIX_PATH}")
echo $CLEAN_PATH
}
15 changes: 8 additions & 7 deletions dockerfiles/che/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,26 @@
# http://www.eclipse.org/legal/epl-v10.html

IMAGE_NAME="eclipse/che-server"
. $(cd "$(dirname "$0")"; pwd)/../build.include
base_dir=$(cd "$(dirname "$0")"; pwd)
. "${base_dir}"/../build.include

# grab assembly
DIR=$(cd "$(dirname "$0")"; pwd)
if [ ! -d "${DIR}/../../assembly/assembly-main/target" ]; then
echo "${ERRO}Have you built assembly/assemby-main in ${DIR}/../assembly/assembly-main 'mvn clean install'?"
echo "${ERROR}Have you built assembly/assemby-main in ${DIR}/../assembly/assembly-main 'mvn clean install'?"
exit 2
fi

# Use of folder
BUILD_ASSEMBLY_ZIP=$(echo ${DIR}/../../assembly/assembly-main/target/eclipse-che-*.tar.gz)
LOCAL_ASSEMBLY_ZIP=${DIR}/eclipse-che.tar.gz
BUILD_ASSEMBLY_ZIP=$(echo "${DIR}"/../../assembly/assembly-main/target/eclipse-che-*.tar.gz)
LOCAL_ASSEMBLY_ZIP="${DIR}"/eclipse-che.tar.gz

if [ -f "${LOCAL_ASSEMBLY_ZIP}" ]; then
rm ${LOCAL_ASSEMBLY_ZIP}
rm "${LOCAL_ASSEMBLY_ZIP}"
fi

echo "Linking assembly ${BUILD_ASSEMBLY_ZIP} --> ${LOCAL_ASSEMBLY_ZIP}"
ln ${BUILD_ASSEMBLY_ZIP} ${LOCAL_ASSEMBLY_ZIP}
ln "${BUILD_ASSEMBLY_ZIP}" "${LOCAL_ASSEMBLY_ZIP}"

init "$@"
build
build
5 changes: 3 additions & 2 deletions dockerfiles/cli/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

IMAGE_NAME="eclipse/che-cli"
base_dir=$(cd "$(dirname "$0")"; pwd)
. $base_dir/../build.include
. "${base_dir}"/../build.include

init "$@"
build


if [ $(skip_tests "$@") = false ]; then
sh $base_dir/test.sh $TAG
sh "${base_dir}"/test.sh $TAG
fi
21 changes: 19 additions & 2 deletions dockerfiles/cli/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,36 @@
# Marian Labuda - Initial Implementation

BATS_BASE_DIR=$(cd "$(dirname "$0")"/..; pwd)
. $BATS_BASE_DIR/build.include
. "${BATS_BASE_DIR}"/build.include
BATS_BASE_DIR=$(get_mount_path "${BATS_BASE_DIR}")

init "$@"
IMAGE_NAME="eclipse/che-bats:$TAG"

DOCKER_RUN_OPTIONS=""
BATS_OPTIONS=""
# run bats with terminal mode (pretty print) if supported by current shell
if [ -t 1 ]; then
DOCKER_RUN_OPTIONS="-t"
BATS_OPTIONS="--pretty"
else
BATS_OPTIONS="--tap"
fi

# Runs functional CLI tests in a docker container.
# Pass a file name of functional bats tests as an argument.
# The file has to be placed in tests folder in directory containing this script
# (Optional) second argument is options for a docker run command.
run_test_in_docker_container() {
docker run $2 -v $BATS_BASE_DIR:$BATS_BASE_DIR -e CLI_IMAGE_TAG=$TAG -e BATS_BASE_DIR=$BATS_BASE_DIR -v /var/run/docker.sock:/var/run/docker.sock $IMAGE_NAME bats $BATS_BASE_DIR/cli/tests/$1
docker_exec run --rm ${DOCKER_RUN_OPTIONS} $2 \
-v "${BATS_BASE_DIR}":/dockerfiles \
-e CLI_IMAGE_TAG=$TAG \
-e BATS_BASE_DIR="${BATS_BASE_DIR}" \
-v /var/run/docker.sock:/var/run/docker.sock \
$IMAGE_NAME bats ${BATS_OPTIONS} /dockerfiles/cli/tests/$1
}


echo "Running tests in container from image $IMAGE_NAME"
echo "Running functional bats tests for CLI prompts and usage"
run_test_in_docker_container cli_prompts_usage_tests.bats
Expand Down
21 changes: 13 additions & 8 deletions dockerfiles/cli/tests/cli_prompts_usage_tests.bats
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,44 @@
# Contributors:
# Marian Labuda - Initial Implementation

source $BATS_BASE_DIR/cli/tests/test_base.sh
load '/bats-support/load.bash'
load '/bats-assert/load.bash'
source /dockerfiles/cli/tests/test_base.sh

@test "test CLI prompt to provide volume for docker sock" {
#GIVEN
prompt_substring="-v /var/run/docker.sock:/var/run/docker.sock"

#WHEN
result=$(docker run $CLI_IMAGE start || true)
run docker run --rm $CLI_IMAGE start

#THEN
[[ $result == *"$prompt_substring"* ]]
assert_failure
assert_output --partial ${prompt_substring}

}

@test "test CLI prompt to provide directory for user data" {
#GIVEN
prompt_substring="-v <YOUR_LOCAL_PATH>:/data"

#WHEN
result=$(docker run -v $SCRIPTS_DIR:/scripts/base -v /var/run/docker.sock:/var/run/docker.sock $CLI_IMAGE start || true)
run docker run --rm -v "${SCRIPTS_DIR}":/scripts/base -v /var/run/docker.sock:/var/run/docker.sock $CLI_IMAGE start

#THEN
[[ $result == *"$prompt_substring"* ]]
assert_failure
assert_output --partial ${prompt_substring}
}

@test "test CLI 'usage' when running container without command" {
#GIVEN
output=$(usage || true)
expected_output="USAGE:"

#WHEN
result=$(docker run -v $SCRIPTS_DIR:/scripts/base -v /var/run/docker.sock:/var/run/docker.sock $CLI_IMAGE || true)
result=$(docker run --rm -v "${SCRIPTS_DIR}":/scripts/base -v /var/run/docker.sock:/var/run/docker.sock $CLI_IMAGE || true)

#THEN
[[ $result == *$usage* ]]
[[ $result == *${expected_output}* ]]
}


Loading