Blob Blame History Raw
#!/bin/bash
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
#   runtest.sh of /CoreOS/rubygem-bundler/unit-tests
#   Description: Runs upstream test suite
#   Author: Iveta Senfeldova <isenfeld@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
#   Copyright (c) 2015 Red Hat, Inc.
#
#   This copyrighted material is made available to anyone wishing
#   to use, modify, copy, or redistribute it subject to the terms
#   and conditions of the GNU General Public License version 2.
#
#   This program is distributed in the hope that it will be
#   useful, but WITHOUT ANY WARRANTY; without even the implied
#   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
#   PURPOSE. See the GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public
#   License along with this program; if not, write to the Free
#   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
#   Boston, MA 02110-1301, USA.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# Include Beaker environment
[ -e /usr/bin/rhts-environment.sh ] && . /usr/bin/rhts-environment.sh
. /usr/share/beakerlib/beakerlib.sh || exit 1

PACKAGES=${PACKAGES:-rubygem-bundler}
REQUIRES=${REQUIRES:-rubygem-thor rubygem-net-http-persistent rubygems rubygems-devel rubygem-rdoc ruby ruby-devel}
BUNDLER=$(rpm -qf --queryformat '%{name}\n' $(which bundler))
COLL_PATH=""
COLL="$(echo $COLLECTIONS|grep -Eo "\b(rh-)?ruby[0-9]*\b"|tail -1)"
RUN_RSPEC="rspec spec"
BUILD_INSTALLED=false

rlJournalStart
    rlPhaseStartSetup
        rlAssertRpm --all
        rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
        rlRun "cp builders.patch $TmpDir" 0
        rlRun "pushd $TmpDir"
        if [[ -n "$COLLECTIONS" ]]
        then
	    rlRun "rlImport distribution/sundry" 0 "Importing sundry library" || rlDie
            rlRun "sundryFetchBuildForInstalledPackage $COLL" 0 "Fetching -build sub-package for $COLL"
            rlRun "sundryFetchBuildForInstalledPackage $COLL" 0 "Fetching -build sub-package for $COLL"
            rlRun "yum -y localinstall $COLL-build*.rpm && BUILD_INSTALLED=true" 0 "Installing $COLL-build package"
        fi
        rlRun "useradd rubyuser" 0 "Adding user rubyuser to the system"
        rlRun "chown -R rubyuser:rubyuser $TmpDir" 0
        rlRun "rlFetchSrcForInstalled $BUNDLER" 0 "Fetching source package for $BUNDLER"
        rlRun "su rubyuser -c \"rpm --define '_topdir $TmpDir' -i $TmpDir/*src.rpm\"" 0 \
            "Installing the source rpm"
        rlRun "su rubyuser -c \"rpmbuild --nodeps --define '_topdir $TmpDir' -bc $TmpDir/SPECS/*spec\"" 0 \
            "Building package"
        VERSION=$(rpm -q --qf "%{VERSION}\n" $BUNDLER | tail -1)
        SRC_PATH="$TmpDir/BUILD/$BUNDLER-$VERSION"

        # if we are in collections we need to set correct path and prepare for enabling ror
        if [[ -n "$COLLECTIONS" ]]
        then
           COLL_PATH=$(which bundler | sed 's/\/usr\/bin\/bundler//')
           RUN_RSPEC="scl enable $(echo $COLLECTIONS | grep -Eo '\b(rh-)?ror[0-9]*\b'|tail -1) 'rspec spec'"
        fi
        rlRun "pushd $SRC_PATH$COLL_PATH/usr/share/gems/gems/bundler-$VERSION/" 0 "Go to gem install dir"

	# on RHEL6/7 without collections  we need to fix valid certs
        if [ -z "$COLLECTIONS" ] && rlIsRHEL '<=7'
        then
            rlRun "su rubyuser -c \"patch spec/support/builders.rb $TmpDir/builders.patch\"" 0 \
            "Patching builders.rb with new valid certificates so some set of tests won't fail"
        else
            rlRun "su rubyuser -c \"tar xzvf $TmpDir/SOURCES/*-specs.tgz\"" 0 "Unpacking specs into install directory"
        fi
        # SPEC file steps:
        # This test does not work, since ruby is configured with --with-ruby-version=''
        # https://github.com/bundler/bundler/issues/2365
        su rubyuser -c "sed -i '/\"fetches gems again after changing the version of Ruby\"/,/end$/{s/^/#/}' spec/install/gems/platform_spec.rb"

        # Test suite needs to run in initialized git repository.
        # https://github.com/carlhuda/bundler/issues/2022
        su rubyuser -c "git init"

	# on RHEL6/7 without collections use additional dependencies from the system
	set -x
        if [ -z "$COLLECTIONS" ] && rlIsRHEL '<=7'
        then
            # Test with system net-http-persistent and thor
            for dependency in net-http-persistent thor
            do
                for fileordir in \
                    /usr/share/gems/gems/$dependency-*/lib/*
                do
                    su rubyuser -c "ln -s -f $fileordir lib/bundler/vendor/$(basename $fileordir)"
                done
            done
            # end of SPEC file steps

            # gems required to run unit tests
            # older versions which should be compatible with ruby-2.0.0, but it's currently without effect, rspec fetches newer versions anyway
            #GEMS="rspec-mocks3.1.0 rspec-support:3.1.0 rspec-expectations:3.1.0 rspec-core:3.1.0 rspec:3.1.0 diff-lcs rack:1.5.2 rake:10.3.2 sinatra:1.4.5"
            GEMS="rspec-mocks rspec-support rspec-expectations rspec-core rspec diff-lcs"
            rlRun "gem install $GEMS" 0 "Installing $GEMS"
        fi
	set +x
    rlPhaseEnd

    rlPhaseStartTest
        rlRun "su rubyuser -c \"$RUN_RSPEC | tee output.log\"" 0 "Run unit tests"
        rlAssertGrep "examples, 0 failures," output.log
    rlPhaseEnd

    rlPhaseStartCleanup
        if [ -z "$COLLECTIONS" ] && rlIsRHEL '<=7'
        then
            rlRun "gem uninstall $GEMS -a -I -x --force" 0 "Removing installed gems"
        fi
        $BUILD_INSTALLED && rlRun "yum -y remove $COLL-build" 0 "Removing $COLL-build package"
        rlRun "userdel -r rubyuser" 0 "Removing rubyuser from the system"
        rlRun "popd ; popd"
        rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
    rlPhaseEnd
rlJournalPrintText
rlJournalEnd