fuel-library/utils/jenkins/fuel_unit_tests.sh
Aleksandr Didenko f5d0e15f48 Don't run syntax/unit tests for removed modules
We're running syntax and unit tests for changed modules only.

But for removed modules, we fail to 'pushd $mod' and thus run test
functions inside current working directory, which is not correct.

We should test if changed module dir exists before trying to run
tests for it.

Fuel-CI: disable

Change-Id: If1ab6850943b7aed7a48479625d8daa0243594f6
Closes-bug: #1435401
2015-03-23 18:12:03 +02:00

67 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
# Some basic checks
if ! [ -d "$WORKSPACE" ] ; then
echo "ERROR: WORKSPACE not found"
exit 1
fi
if [ -z "$PUPPET_GEM_VERSION" ] ; then
export PUPPET_GEM_VERSION='~> 3.4.0'
fi
# Check for bundle and exit if failed
bundle --version || exit 1
# Check if disabled modules list if available
test -f $WORKSPACE/utils/jenkins/modules.disable_rspec || exit 1
export GEM_HOME=$WORKSPACE/.bundled_gems
# Function that runs rake spec using bundle
function rake_spec {
MODULE=`basename $(pwd)`
echo -e "\nChecking module $MODULE"
if ! [ -f Gemfile ] ; then
echo "Gemfile not found. Skipping unit tests."
return 0
fi
if ! [ -f Rakefile ] ; then
echo "Rakefile not found. Skipping unit tests."
return 0
fi
if grep -qx $MODULE $WORKSPACE/utils/jenkins/modules.disable_rspec ; then
echo "Unit tests are disabled for $MODULE module"
return 0
fi
bundle update
bundle exec rake spec SPEC_OPTS='--format documentation --tty --color'
return $?
}
# Iterate over the changed modules and run unit tests for them
failed_modules=""
modules=$(git diff --name-only HEAD~ | grep -o 'deployment/puppet/[^/]*/' | sort -u)
git diff --name-only HEAD~ &>/dev/null || exit 1
for mod in $modules; do
if [ -d $mod ] ; then
pushd $mod &> /dev/null
rake_spec || failed_modules="$failed_modules\n$mod"
popd &>/dev/null
fi
done
if [ -z "$failed_modules" ] ; then
echo -e "\nRSpec Tests SUCCEEDED: No errors found.\n"
exit 0
else
echo -e "\nRSpec Tests FAILED for the following modules:"
echo -e "$failed_modules\n"
exit 1
fi