Skip to content

Commit a888ccb

Browse files
tikitaviAndrey-mp
authored andcommitted
run unit tests for webui (tungstenfabric#52)
* run unit tests for webui * rework unittests for webui
1 parent 9db45be commit a888ccb

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

scripts/run-tests.sh

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ scriptdir=$(realpath $(dirname "$0"))
77

88
if [[ "$TARGET" == 'ui' ]]; then
99
echo "INFO: Running web ui tests"
10+
$scriptdir/webui_ut/run-tests.sh
1011
elif [[ "$TARGET" == 'vcenter' ]]; then
1112
echo "INFO: Running vcenter tests"
1213
else

scripts/webui_ut/run-tests.sh

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/bin/bash -ex
2+
3+
scriptdir=$(realpath $(dirname "$0"))
4+
5+
src_root=/root/contrail
6+
cd $src_root
7+
logs_path='/root/contrail/logs'
8+
test_reports_dir="$logs_path/test-reports"
9+
coverage_reports_dir="$logs_path/coverage-reports"
10+
mkdir -p "$logs_path"
11+
mkdir -p "$test_reports_dir"
12+
mkdir -p "$coverage_reports_dir"
13+
14+
function pre_test_setup() {
15+
# Add Google Chrome repo
16+
cat <<EOF > /etc/yum.repos.d/Google-Chrome.repo
17+
#Google-Chrome.repo
18+
19+
[google-chrome]
20+
name=google-chrome
21+
baseurl=http://dl.google.com/linux/chrome/rpm/stable/x86_64
22+
gpgcheck=0
23+
enabled=1
24+
EOF
25+
26+
# Install the Development tools package group and additional packages
27+
yum install -y "@Development tools" python-lxml wget google-chrome-stable
28+
29+
#Update the featurePkg path in contrail-web-core/config/config.global.js with Controller, Storage and Server Manager features
30+
cd $src_root/contrail-web-core
31+
32+
# Controller
33+
cat config/config.global.js | sed -e "s%/usr/src/contrail/contrail-web-controller%$src_root/contrail-web-controller%" > $src_root/contrail-web-core/config/config.global.js.tmp
34+
cp $src_root/contrail-web-core/config/config.global.js.tmp $src_root/contrail-web-core/config/config.global.js
35+
rm $src_root/contrail-web-core/config/config.global.js.tmp
36+
touch config/config.global.js
37+
38+
#fetch dependent packages
39+
make fetch-pkgs-dev
40+
}
41+
42+
function build_unittest() {
43+
#Setup the Prod Environment
44+
make prod-env REPO=webController
45+
#Setup the Test Environment
46+
make test-env REPO=webController
47+
48+
# Run Controller related Unit Testcase
49+
cd $src_root/contrail-web-controller
50+
./webroot/test/ui/run_tests.sh 2>&1 | tee $logs_path/web_controller_unittests.log
51+
}
52+
53+
function copy_reports(){
54+
cd $src_root
55+
report_dir=webroot/test/ui/reports
56+
57+
echo "info: gathering XML test reports..."
58+
cp -p contrail-web*/$report_dir/tests/*-test-results.xml $test_reports_dir || true
59+
60+
echo "info: gathering XML coverage reports..."
61+
cp -p /root/contrail/contrail-web-controller/$report_dir/coverage/*/*/cobertura-coverage.xml $coverage_reports_dir/controller-cobertura-coverage.xml || true
62+
}
63+
64+
#This installs node, npm and does a fetch_packages, make prod env, test setup
65+
pre_test_setup
66+
67+
# run unit test case
68+
build_unittest
69+
70+
# copy the generated reports to specific directory
71+
copy_reports
72+
73+
res=$?
74+
if [[ "$res" != '0' ]]; then
75+
echo "ERROR: some UT failed"
76+
fi
77+
echo "INFO: Unit test log is available at contrail/logs/web_controller_unittests.log"
78+
echo "INFO: Test report is available at contrail/logs/test-reports/web-controller-test-results.xml"
79+
echo "INFO: Coverage report is available at contrail/logs/coverage-reports/controller-cobertura-coverage.xml"
80+
exit $res

0 commit comments

Comments
 (0)