|
| 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 | +} |
0 commit comments