From d94c2dc29bdc4991f0e4afec86eaca6ce17d7862 Mon Sep 17 00:00:00 2001 From: Vitaly Kramskikh Date: Fri, 5 Feb 2016 19:28:22 +0300 Subject: [PATCH] Move UI-related testing logic to a separate file Implements: blueprint separate-fuel-ui-repo Change-Id: I509b336785f39066f5673f17af3c97b61e7f3be2 --- package.json | 2 +- run_ui_func_tests.sh | 145 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+), 1 deletion(-) create mode 100755 run_ui_func_tests.sh diff --git a/package.json b/package.json index 2831fa91e..7d26b85ac 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "lint": "gulp lint", "test": "npm run unit-tests && npm run func-tests", "unit-tests": "gulp unit-tests", - "func-tests": "../run_tests.sh --ui-func", + "func-tests": "./run_ui_func_tests.sh", "prepublish": "gulp build" }, "dependencies": { diff --git a/run_ui_func_tests.sh b/run_ui_func_tests.sh new file mode 100755 index 000000000..c5b9aa97c --- /dev/null +++ b/run_ui_func_tests.sh @@ -0,0 +1,145 @@ +#!/bin/bash + +# Copyright 2016 Mirantis, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +set -eu + +function usage { + echo "Usage: $0 [OPTION]..." + echo "Run Fuel UI functional tests" + echo "" + echo " -h, --help Print this usage message" + echo " --no-ui-compression Skip UI compression" + echo " --no-nailgun-start Skip Nailgun start" + exit +} + +no_ui_compression=0 +no_nailgun_start=0 +tests= + +function process_options { + for arg in $@; do + case "$arg" in + -h|--help) usage;; + --no-ui-compression) no_ui_compression=1;; + --no-nailgun-start) no_nailgun_start=1;; + -*);; + *) tests="$tests $arg" + esac + done +} + +FUEL_WEB_ROOT=$(readlink -f $(dirname $0)/..) +NAILGUN_ROOT=$FUEL_WEB_ROOT/nailgun + +ARTIFACTS=${ARTIFACTS:-`pwd`/test_run} +mkdir -p $ARTIFACTS + +export NAILGUN_STATIC=$ARTIFACTS/static +export NAILGUN_TEMPLATES=$NAILGUN_STATIC + +export NAILGUN_PORT=${NAILGUN_PORT:-5544} +export NAILGUN_START_MAX_WAIT_TIME=${NAILGUN_START_MAX_WAIT_TIME:-30} + +export NAILGUN_DB_HOST=${NAILGUN_DB_HOST:-/var/run/postgresql} +export NAILGUN_DB=${NAILGUN_DB:-nailgun} +export NAILGUN_DB_USER=${NAILGUN_DB_USER:-nailgun} +export NAILGUN_DB_USERPW=${NAILGUN_DB_USERPW:-nailgun} + +export DB_ROOT=${DB_ROOT:-postgres} + +export NAILGUN_FIXTURE_FILES="${NAILGUN_ROOT}/nailgun/fixtures/sample_environment.json ${NAILGUN_ROOT}/nailgun/fixtures/sample_plugins.json" + +export NAILGUN_CHECK_URL='/api/version' + + +# Run UI functional tests. +# +# Arguments: +# +# $@ -- tests to be run; with no arguments all tests will be run +function run_ui_func_tests { + local GULP="./node_modules/.bin/gulp" + local TESTS_DIR=static/tests/functional # FIXME(vkramskikh): absolute path should be used + local TESTS=$TESTS_DIR/test_*.js + + pushd "$FUEL_WEB_ROOT" > /dev/null + tox -e cleanup + popd > /dev/null + + if [ $# -ne 0 ]; then + TESTS=$@ + fi + + if [ $no_ui_compression -ne 1 ]; then + echo "Compressing UI... " + ${GULP} build --no-sourcemaps --extra-entries=sinon --static-dir=$NAILGUN_STATIC + if [ $? -ne 0 ]; then + return 1 + fi + else + echo "Using compressed UI from $NAILGUN_STATIC" + if [ ! -f "$NAILGUN_STATIC/index.html" ]; then + echo "Cannot find compressed UI. Don't use --no-ui-compression key" + return 1 + fi + fi + + if [ $no_nailgun_start -ne 1 ]; then + pushd "$FUEL_WEB_ROOT" > /dev/null + tox -e stop + popd > /dev/null + fi + + local result=0 + + for testcase in $TESTS; do + pushd "$FUEL_WEB_ROOT" > /dev/null + tox -e cleanup + popd > /dev/null + + + local server_log=`mktemp /tmp/test_nailgun_ui_server.XXXX` + if [ $no_nailgun_start -ne 1 ]; then + pushd "$FUEL_WEB_ROOT" > /dev/null + tox -e start + popd > /dev/null + fi + + SERVER_PORT=$NAILGUN_PORT \ + ARTIFACTS=$ARTIFACTS \ + ${GULP} functional-tests --suites=$testcase || result=1 + + if [ $no_nailgun_start -ne 1 ]; then + pushd "$FUEL_WEB_ROOT" > /dev/null + tox -e stop + popd > /dev/null + fi + + if [ $result -ne 0 ]; then + mv $server_log $ARTIFACTS/app.log + break + fi + rm $server_log + done + + return $result +} + + +# parse command line arguments and run the tests +process_options $@ +run_ui_func_tests $tests