Fuel Web UI
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

run_ui_func_tests.sh 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #!/bin/bash
  2. # Copyright 2016 Mirantis, Inc.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  5. # not use this file except in compliance with the License. You may obtain
  6. # a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. # License for the specific language governing permissions and limitations
  14. # under the License.
  15. set -eu
  16. function usage {
  17. echo "Usage: $0 [OPTION]..."
  18. echo "Run Fuel UI functional tests"
  19. echo ""
  20. echo " -h, --help Print this usage message"
  21. echo " --no-ui-build Skip UI build"
  22. echo " --no-nailgun-start Skip Nailgun start"
  23. exit
  24. }
  25. no_ui_build=0
  26. no_nailgun_start=0
  27. tests=
  28. function process_options {
  29. for arg in $@; do
  30. case "$arg" in
  31. -h|--help) usage;;
  32. --no-ui-build) no_ui_build=1;;
  33. --no-nailgun-start) no_nailgun_start=1;;
  34. -*);;
  35. *) tests="$tests $arg"
  36. esac
  37. done
  38. }
  39. FUEL_WEB_ROOT="$(unset CDPATH && cd ${FUEL_WEB_ROOT:-$(dirname $0)/../fuel-web} && pwd)"
  40. NAILGUN_ROOT=$FUEL_WEB_ROOT/nailgun
  41. ARTIFACTS=${ARTIFACTS:-`pwd`/test_run/ui_func}
  42. mkdir -p $ARTIFACTS
  43. export FAIL_FAST=${FAIL_FAST:-true}
  44. export NAILGUN_STATIC=$ARTIFACTS/static
  45. export NAILGUN_TEMPLATES=$NAILGUN_STATIC
  46. export NAILGUN_PORT=${NAILGUN_PORT:-5544}
  47. export NAILGUN_START_MAX_WAIT_TIME=${NAILGUN_START_MAX_WAIT_TIME:-30}
  48. export NAILGUN_DB_HOST=${NAILGUN_DB_HOST:-/var/run/postgresql}
  49. export NAILGUN_DB=${NAILGUN_DB:-nailgun}
  50. export NAILGUN_DB_USER=${NAILGUN_DB_USER:-nailgun}
  51. export NAILGUN_DB_USERPW=${NAILGUN_DB_USERPW:-nailgun}
  52. export DB_ROOT=${DB_ROOT:-postgres}
  53. export NAILGUN_FIXTURE_FILES="${NAILGUN_ROOT}/nailgun/fixtures/sample_environment.json ${NAILGUN_ROOT}/nailgun/fixtures/sample_plugins.json"
  54. export NAILGUN_CHECK_URL='/api/version'
  55. # Run UI functional tests.
  56. #
  57. # Arguments:
  58. #
  59. # $@ -- tests to be run; with no arguments all tests will be run
  60. function run_ui_func_tests {
  61. local GULP="./node_modules/.bin/gulp"
  62. local TESTS_DIR=static/tests/functional # FIXME(vkramskikh): absolute path should be used
  63. local TESTS=$TESTS_DIR/test_*.js
  64. pushd "$FUEL_WEB_ROOT" > /dev/null
  65. tox -e cleanup
  66. popd > /dev/null
  67. if [ $# -ne 0 ]; then
  68. TESTS=$@
  69. fi
  70. if [ $no_ui_build -ne 1 ]; then
  71. echo "Building UI..."
  72. ${GULP} build --no-sourcemaps --extra-entries=sinon --static-dir=$NAILGUN_STATIC
  73. else
  74. echo "Using pre-built UI from $NAILGUN_STATIC"
  75. if [ ! -f "$NAILGUN_STATIC/index.html" ]; then
  76. echo "Cannot find pre-built UI. Don't use --no-ui-build key"
  77. return 1
  78. fi
  79. fi
  80. echo "Building tests..."
  81. ${GULP} intern:transpile
  82. if [ $no_nailgun_start -ne 1 ]; then
  83. pushd "$FUEL_WEB_ROOT" > /dev/null
  84. tox -e stop
  85. popd > /dev/null
  86. fi
  87. local result=0
  88. for testcase in $TESTS; do
  89. pushd "$FUEL_WEB_ROOT" > /dev/null
  90. tox -e cleanup
  91. popd > /dev/null
  92. if [ $no_nailgun_start -ne 1 ]; then
  93. pushd "$FUEL_WEB_ROOT" > /dev/null
  94. tox -e start
  95. popd > /dev/null
  96. fi
  97. SERVER_PORT=$NAILGUN_PORT \
  98. ARTIFACTS=$ARTIFACTS \
  99. ${GULP} functional-tests --no-transpile --suites=$testcase || result=1
  100. if [ $no_nailgun_start -ne 1 ]; then
  101. pushd "$FUEL_WEB_ROOT" > /dev/null
  102. tox -e stop
  103. popd > /dev/null
  104. fi
  105. if [ $FAIL_FAST = true ] ; then
  106. if [ $result -ne 0 ]; then
  107. break
  108. fi
  109. fi
  110. done
  111. return $result
  112. }
  113. # parse command line arguments and run the tests
  114. process_options $@
  115. run_ui_func_tests $tests