Skip to content

Commit 5710682

Browse files
author
Roman Iuvshyn
authored
enable and fix existing and add some more tests CLI tests. (eclipse-che#5304)
* enable, fix and add more CLI tests.
1 parent a50cf74 commit 5710682

11 files changed

Lines changed: 481 additions & 81 deletions

dockerfiles/cli/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
version/nightly/images
2+
tests/testrun/*

dockerfiles/cli/test.sh

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,18 @@ run_test_in_docker_container() {
3737
$IMAGE_NAME bats ${BATS_OPTIONS} /dockerfiles/cli/tests/$1
3838
}
3939

40-
4140
echo "Running tests in container from image $IMAGE_NAME"
4241
echo "Running functional bats tests for CLI prompts and usage"
43-
#run_test_in_docker_container cli_prompts_usage_tests.bats
42+
run_test_in_docker_container cli_prompts_usage_tests.bats
43+
echo "Running functionals bats tests for config command"
44+
run_test_in_docker_container cmd_config_tests.bats
45+
echo "Running functionals bats tests for info command"
46+
run_test_in_docker_container cmd_info_tests.bats
4447
echo "Running functional bats tests for init and destroy commands"
45-
#run_test_in_docker_container cmd_init_destroy_tests.bats
46-
echo "Running functionals bats tests for start command"
47-
run_test_in_docker_container cmd_start_tests.bats --net=host
48+
run_test_in_docker_container cmd_init_destroy_tests.bats
49+
echo "Running functionals bats tests for start, stop, restart command"
50+
run_test_in_docker_container cmd_start_stop_restart_tests.bats --net=host
51+
echo "Running functionals bats tests for backup / restore commands"
52+
run_test_in_docker_container cmd_backup_restore_tests.bats
53+
echo "Running functionals bats tests for offline command"
54+
run_test_in_docker_container cmd_offline_tests.bats

dockerfiles/cli/tests/cli_prompts_usage_tests.bats

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,19 @@ source /dockerfiles/cli/tests/test_base.sh
1717
prompt_substring="-v /var/run/docker.sock:/var/run/docker.sock"
1818

1919
#WHEN
20-
run docker run --rm $CLI_IMAGE start
20+
run execute_cli_command --che-cli-mount-scripts=false --che-cli-use-docker-sock=false --che-cli-command=start
2121

2222
#THEN
2323
assert_failure
2424
assert_output --partial ${prompt_substring}
25-
2625
}
2726

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

3231
#WHEN
33-
run docker run --rm -v "${SCRIPTS_DIR}":/scripts/base -v /var/run/docker.sock:/var/run/docker.sock $CLI_IMAGE start
32+
run execute_cli_command --che-cli-command=start
3433

3534
#THEN
3635
assert_failure
@@ -42,10 +41,8 @@ source /dockerfiles/cli/tests/test_base.sh
4241
expected_output="USAGE:"
4342

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

4746
#THEN
4847
[[ $result == *${expected_output}* ]]
4948
}
50-
51-
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
#!/usr/bin/env bats
2+
# Copyright (c) 2017 Codenvy, S.A.
3+
# All rights reserved. This program and the accompanying materials
4+
# are made available under the terms of the Eclipse Public License v1.0
5+
# which accompanies this distribution, and is available at
6+
# http://www.eclipse.org/legal/epl-v10.html
7+
#
8+
# Contributors:
9+
# Roman Iuvshyn
10+
11+
source /dockerfiles/cli/tests/test_base.sh
12+
13+
# Kill running che server instance if there is any to be able to run tests
14+
setup() {
15+
kill_running_named_container che
16+
remove_named_container che
17+
}
18+
19+
teardown() {
20+
kill_running_named_container che
21+
remove_named_container che
22+
}
23+
24+
@test "test cli 'backup' command: backup fail if che is running" {
25+
#GIVEN
26+
if [ ! port_is_free 8080 ]; then
27+
[ "$status" -eq 1 ]
28+
[ "$output" = "Default port 8080 for che server is used. Cannot run this test on default che server port" ]
29+
fi
30+
tmp_path="${TESTRUN_DIR}"/cli_cmd_backup_fail_if_che_is_running
31+
mkdir -p "${tmp_path}"
32+
execute_cli_command --che-data-path=${tmp_path} --che-cli-command=start --che-cli-extra-options="--skip:nightly --skip:pull"
33+
check_che_state
34+
#WHEN
35+
result=$(execute_cli_command --che-data-path=${tmp_path} --che-cli-command=backup --che-cli-extra-options="--skip:nightly --skip:pull" || true)
36+
37+
#THEN
38+
[[ $result == *"che is running. Stop before performing a backup."* ]]
39+
}
40+
41+
@test "test cli 'restore' command: restore fail if che is running" {
42+
#GIVEN
43+
if [ ! port_is_free 8080 ]; then
44+
[ "$status" -eq 1 ]
45+
[ "$output" = "Default port 8080 for che server is used. Cannot run this test on default che server port" ]
46+
fi
47+
tmp_path="${TESTRUN_DIR}"/cli_cmd_restore_fail_if_che_is_running
48+
mkdir -p "${tmp_path}"
49+
execute_cli_command --che-data-path=${tmp_path} --che-cli-command=start --che-cli-extra-options="--skip:nightly --skip:pull"
50+
check_che_state
51+
#WHEN
52+
result=$(execute_cli_command --che-data-path=${tmp_path} --che-cli-command=restore --che-cli-extra-options="--quiet --skip:nightly --skip:pull")
53+
54+
#THEN
55+
[[ $result == *"Eclipse Che is running. Stop before performing a restore."* ]]
56+
}
57+
58+
@test "test cli 'restore' command: restore fail if no backup found" {
59+
#GIVEN
60+
if [ ! port_is_free 8080 ]; then
61+
[ "$status" -eq 1 ]
62+
[ "$output" = "Default port 8080 for che server is used. Cannot run this test on default che server port" ]
63+
fi
64+
tmp_path="${TESTRUN_DIR}"/cli_cmd_restore_fail_if_no_backup_found
65+
mkdir -p "${tmp_path}"
66+
execute_cli_command --che-data-path=${tmp_path} --che-cli-command=start --che-cli-extra-options="--skip:nightly --skip:pull"
67+
check_che_state
68+
execute_cli_command --che-data-path=${tmp_path} --che-cli-command=stop --che-cli-extra-options="--skip:nightly --skip:pull"
69+
70+
#WHEN
71+
result=$(execute_cli_command --che-data-path=${tmp_path} --che-cli-command=restore --che-cli-extra-options="--quiet --skip:nightly --skip:pull")
72+
73+
#THEN
74+
[[ $result == *"Backup files not found. To do restore please do backup first."* ]]
75+
}
76+
77+
@test "test cli 'backup / restore' commands" {
78+
# TEST BACKUP
79+
#GIVEN
80+
if [ ! port_is_free 8080 ]; then
81+
[ "$status" -eq 1 ]
82+
[ "$output" = "Default port 8080 for che server is used. Cannot run this test on default che server port" ]
83+
fi
84+
tmp_path="${TESTRUN_DIR}"/cli_cmd_backup_do_backup_restore
85+
container_tmp_path="${CONTAINER_TESTRUN_DIR}"/cli_cmd_backup_do_backup_restore
86+
workspace_name="backup-restore"
87+
mkdir -p "${tmp_path}"
88+
#start che
89+
execute_cli_command --che-data-path=${tmp_path} --che-cli-command=start --che-cli-extra-options="--skip:nightly --skip:pull"
90+
check_che_state
91+
#create a workspace
92+
93+
ws_create=$(curl 'http://'${ip_address}':8080/api/workspace?namespace=che&attribute=stackId:java-default' -H 'Content-Type: application/json;charset=UTF-8' -H 'Accept: application/json, text/plain, */*' --data-binary '{"defaultEnv":"wksp-1p0b","environments":{"wksp-1p0b":{"recipe":{"location":"eclipse/ubuntu_jdk8","type":"dockerimage"},"machines":{"dev-machine":{"servers":{},"agents":["org.eclipse.che.exec","org.eclipse.che.terminal","org.eclipse.che.ws-agent","org.eclipse.che.ssh"],"attributes":{"memoryLimitBytes":"2147483648"}}}}},"projects":[],"commands":[{"commandLine":"mvn clean install -f ${current.project.path}","name":"build","type":"mvn","attributes":{"goal":"Build","previewUrl":""}}],"name":"backup-restore","links":[]}' --compressed)
94+
[[ "$ws_create" == *"created"* ]]
95+
[[ "$ws_create" == *"STOPPED"* ]]
96+
#stop che
97+
execute_cli_command --che-data-path=${tmp_path} --che-cli-command=stop --che-cli-extra-options="--skip:nightly --skip:pull"
98+
99+
#WHEN
100+
backup=$(execute_cli_command --che-data-path=${tmp_path} --che-cli-command=backup --che-cli-extra-options="--skip:nightly --skip:pull")
101+
102+
#THEN
103+
[[ "$backup" == *"Saving codenvy data..."* ]]
104+
[[ "$backup" == *"che data saved in ${tmp_path}/backup/che_backup.tar.gz"* ]]
105+
[[ -f "${container_tmp_path}"/backup/che_backup.tar.gz ]]
106+
107+
# TEST RESTORE
108+
#GIVEN
109+
#destroy to wipe data
110+
execute_cli_command --che-data-path=${tmp_path} --che-cli-command=destroy --che-cli-extra-options="--quiet --skip:nightly --skip:pull"
111+
[[ ! -d "${container_tmp_path}"/instance ]]
112+
#WHEN
113+
#perform restore from backup
114+
restore=$(execute_cli_command --che-data-path=${tmp_path} --che-cli-command=restore --che-cli-extra-options="--quiet --skip:nightly --skip:pull")
115+
116+
#THEN
117+
[[ "$restore" == *"Recovering Eclipse Che data..."* ]]
118+
[[ -d "${container_tmp_path}"/instance ]]
119+
[[ -d "${container_tmp_path}"/instance/data ]]
120+
121+
#WHEN
122+
execute_cli_command --che-data-path=${tmp_path} --che-cli-command=start --che-cli-extra-options="--skip:nightly --skip:pull"
123+
check_che_state
124+
125+
#THEN
126+
[[ "$(curl -fsS http://${ip_address}:8080/api/workspace)" == *"$workspace_name"* ]]
127+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bats
2+
# Copyright (c) 2017 Codenvy, S.A.
3+
# All rights reserved. This program and the accompanying materials
4+
# are made available under the terms of the Eclipse Public License v1.0
5+
# which accompanies this distribution, and is available at
6+
# http://www.eclipse.org/legal/epl-v10.html
7+
#
8+
# Contributors:
9+
# Roman Iuvshyn
10+
11+
load '/bats-support/load.bash'
12+
load '/bats-assert/load.bash'
13+
source /dockerfiles/cli/tests/test_base.sh
14+
15+
@test "test CLI 'config' command" {
16+
#GIVEN
17+
tmp_path="${TESTRUN_DIR}"/cli_cmd_config
18+
container_tmp_path="${CONTAINER_TESTRUN_DIR}"/cli_cmd_config
19+
20+
#WHEN
21+
execute_cli_command --che-data-path=${tmp_path} --che-cli-command=config --che-cli-extra-options="--skip:nightly --skip:pull"
22+
23+
#THEN
24+
[[ -d "${container_tmp_path}"/docs ]]
25+
[[ -e "${container_tmp_path}"/che.env ]]
26+
[[ -e "${container_tmp_path}"/cli.log ]]
27+
[[ -d "${container_tmp_path}"/instance ]]
28+
[[ -d "${container_tmp_path}"/instance/config ]]
29+
[[ -f "${container_tmp_path}"/instance/config/che.env ]]
30+
[[ -d "${container_tmp_path}"/instance/data ]]
31+
[[ -d "${container_tmp_path}"/instance/logs ]]
32+
[[ -d "${container_tmp_path}"/instance/stacks ]]
33+
[[ -d "${container_tmp_path}"/instance/templates ]]
34+
[[ -f "${container_tmp_path}"/instance/docker-compose-container.yml ]]
35+
[[ -f "${container_tmp_path}"/instance/che.ver.do_not_modify ]]
36+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bats
2+
# Copyright (c) 2017 Codenvy, S.A.
3+
# All rights reserved. This program and the accompanying materials
4+
# are made available under the terms of the Eclipse Public License v1.0
5+
# which accompanies this distribution, and is available at
6+
# http://www.eclipse.org/legal/epl-v10.html
7+
#
8+
# Contributors:
9+
# Roman Iuvshyn
10+
11+
load '/bats-support/load.bash'
12+
load '/bats-assert/load.bash'
13+
source /dockerfiles/cli/tests/test_base.sh
14+
15+
@test "test CLI 'info' command" {
16+
#GIVEN
17+
tmp_path="${TESTRUN_DIR}"/cli_cmd_info
18+
expected_output_1="CLI:"
19+
expected_output_2="Mounts:"
20+
expected_output_3="System:"
21+
expected_output_4="Internal:"
22+
expected_output_5="Image Registry:"
23+
24+
#WHEN
25+
result=$(execute_cli_command --che-data-path=${tmp_path} --che-cli-command=info --che-cli-extra-options="--skip:nightly --skip:pull")
26+
27+
#THEN
28+
[[ $result == *${expected_output_1}* ]]
29+
[[ $result == *${expected_output_2}* ]]
30+
[[ $result == *${expected_output_3}* ]]
31+
[[ $result == *${expected_output_4}* ]]
32+
[[ $result == *${expected_output_5}* ]]
33+
}

dockerfiles/cli/tests/cmd_init_destroy_tests.bats

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ source /dockerfiles/cli/tests/test_base.sh
1818
mkdir -p "${tmp_path}"
1919

2020
#WHEN
21-
docker run --rm -v "${SCRIPTS_DIR}":/scripts/base -v /var/run/docker.sock:/var/run/docker.sock -v "${tmp_path}":/data $CLI_IMAGE init --skip:nightly --skip:pull
21+
execute_cli_command --che-data-path=${tmp_path} --che-cli-command=init --che-cli-extra-options="--skip:nightly --skip:pull"
2222

2323
#THEN
2424
[[ -d "${container_tmp_path}"/docs ]]
@@ -27,8 +27,8 @@ source /dockerfiles/cli/tests/test_base.sh
2727
[[ -e "${container_tmp_path}"/cli.log ]]
2828

2929
#WHEN
30-
docker run --rm -v "${SCRIPTS_DIR}":/scripts/base -v /var/run/docker.sock:/var/run/docker.sock -v "${tmp_path}":/data $CLI_IMAGE destroy --quiet --skip:nightly --skip:pull
31-
30+
execute_cli_command --che-data-path=${tmp_path} --che-cli-command=destroy --che-cli-extra-options="--quiet --skip:nightly --skip:pull"
31+
3232
#THEN
3333
[[ ! -d "${container_tmp_path}"/docs ]]
3434
[[ ! -d "${container_tmp_path}"/instance ]]
@@ -43,8 +43,8 @@ source /dockerfiles/cli/tests/test_base.sh
4343
tmp_path="${TESTRUN_DIR}"/init-destroy2
4444
container_tmp_path="${CONTAINER_TESTRUN_DIR}"/init-destroy2
4545

46-
#WHEN
47-
docker run --rm -v "${SCRIPTS_DIR}":/scripts/base -v /var/run/docker.sock:/var/run/docker.sock -v "${tmp_path}":/data $CLI_IMAGE init --skip:nightly --skip:pull 1>/dev/null
46+
#WHEN
47+
execute_cli_command --che-data-path=${tmp_path} --che-cli-command=init --che-cli-extra-options="--skip:nightly --skip:pull 1>/dev/null"
4848

4949
#THEN
5050
[[ -e "${container_tmp_path}" ]]
@@ -54,7 +54,7 @@ source /dockerfiles/cli/tests/test_base.sh
5454
[[ -e "${container_tmp_path}"/cli.log ]]
5555

5656
#WHEN
57-
docker run --rm -v "${SCRIPTS_DIR}":/scripts/base -v /var/run/docker.sock:/var/run/docker.sock -v "${tmp_path}":/data $CLI_IMAGE destroy --skip:nightly --skip:pull --quiet 1>/dev/null
57+
execute_cli_command --che-data-path=${tmp_path} --che-cli-command=destroy --che-cli-extra-options="--quiet --skip:nightly --skip:pull 1>/dev/null"
5858

5959
#THEN
6060
[[ ! -d "${container_tmp_path}"/docs ]]
@@ -73,7 +73,7 @@ source /dockerfiles/cli/tests/test_base.sh
7373
mkdir -p "${tmp_path}"
7474

7575
#WHEN
76-
docker run --rm -v "${SCRIPTS_DIR}":/scripts/base -v /var/run/docker.sock:/var/run/docker.sock -v "${tmp_path}":/data $CLI_IMAGE init --skip:nightly --skip:pull 1>/dev/null
76+
execute_cli_command --che-data-path=${tmp_path} --che-cli-command=init --che-cli-extra-options="--skip:nightly --skip:pull 1>/dev/null"
7777
remove_named_container $CLI_CONTAINER
7878

7979
#THEN
@@ -83,7 +83,7 @@ source /dockerfiles/cli/tests/test_base.sh
8383
[[ -e "${container_tmp_path}"/cli.log ]]
8484

8585
#WHEN
86-
docker run --rm -v "${SCRIPTS_DIR}":/scripts/base -v /var/run/docker.sock:/var/run/docker.sock -v "${tmp_path}":/data $CLI_IMAGE destroy --skip:nightly --skip:pull --quiet --cli 1>/dev/null
86+
execute_cli_command --che-data-path=${tmp_path} --che-cli-command=destroy --che-cli-extra-options="--quiet --skip:nightly --skip:pull --cli 1>/dev/null"
8787

8888
#THEN
8989
[[ ! -d "${container_tmp_path}"/docs ]]
@@ -101,7 +101,7 @@ source /dockerfiles/cli/tests/test_base.sh
101101
container_tmp_path="${CONTAINER_TESTRUN_DIR}"/init-destroy4
102102

103103
#WHEN
104-
docker run --rm -v "${SCRIPTS_DIR}":/scripts/base -v /var/run/docker.sock:/var/run/docker.sock -v "${tmp_path}":/data $CLI_IMAGE init --skip:nightly --skip:pull 1>/dev/null
104+
execute_cli_command --che-data-path=${tmp_path} --che-cli-command=init --che-cli-extra-options="--skip:nightly --skip:pull 1>/dev/null"
105105

106106
#THEN
107107
[[ -d "${container_tmp_path}" ]]
@@ -111,14 +111,12 @@ source /dockerfiles/cli/tests/test_base.sh
111111
[[ -e "${container_tmp_path}"/cli.log ]]
112112

113113
#WHEN
114-
docker run --rm -v "${SCRIPTS_DIR}":/scripts/base -v /var/run/docker.sock:/var/run/docker.sock -v "${tmp_path}":/data $CLI_IMAGE destroy --skip:nightly --skip:pull --quiet --cli 1>/dev/null
115-
114+
execute_cli_command --che-data-path=${tmp_path} --che-cli-command=destroy --che-cli-extra-options="--skip:nightly --skip:pull --quiet --cli 1>/dev/null"
115+
116116
#THEN
117117
[[ ! -d "${container_tmp_path}"/docs ]]
118118
[[ ! -d "${container_tmp_path}"/instance ]]
119119
[[ ! -e "${container_tmp_path}"/che.env ]]
120120
[[ ! -e "${container_tmp_path}"/cli.log ]]
121121
rm -rf "${container_tmp_path}"
122-
123122
}
124-

0 commit comments

Comments
 (0)