Blame tests/bundler-unit-tests/runtest.sh

5bae896
#!/bin/bash
5bae896
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
5bae896
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5bae896
#
5bae896
#   Description: Runs upstream test suite
5bae896
#   Author: Miroslav Vadkerti <mvadkert@redhat.com>
5bae896
#
5bae896
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5bae896
#
5bae896
#   Copyright (c) 2018 Red Hat, Inc.
5bae896
#
5bae896
#   This copyrighted material is made available to anyone wishing
5bae896
#   to use, modify, copy, or redistribute it subject to the terms
5bae896
#   and conditions of the GNU General Public License version 2.
5bae896
#
5bae896
#   This program is distributed in the hope that it will be
5bae896
#   useful, but WITHOUT ANY WARRANTY; without even the implied
5bae896
#   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
5bae896
#   PURPOSE. See the GNU General Public License for more details.
5bae896
#
5bae896
#   You should have received a copy of the GNU General Public
5bae896
#   License along with this program; if not, write to the Free
5bae896
#   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
5bae896
#   Boston, MA 02110-1301, USA.
5bae896
#
5bae896
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5bae896
5bae896
# Include Beaker environment
5bae896
. /usr/share/beakerlib/beakerlib.sh || { echo "error: Beakerlib is not installed"; exit 1; }
5bae896
5bae896
PACKAGE=rubygem-bundler
5bae896
REQUIRES="rubygem-rspec ruby-devel rubygems-devel gcc"
5bae896
VERSION=$(rpm -q --qf "%{VERSION}\n" $PACKAGE | tail -1)
5bae896
RUNUSER="rubyuser"
5bae896
5bae896
RunAsUser() {
5bae896
    rlRun "su $RUNUSER -c \"$1\"" $2 "$3"
5bae896
}
5bae896
5bae896
rlJournalStart
5bae896
    rlPhaseStartSetup
5bae896
        rlAssertRpm --all
5bae896
        rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
5bae896
        rlRun "pushd $TmpDir"
5bae896
        rlRun "useradd rubyuser" 0 "Adding user rubyuser to the system"
5bae896
        rlRun "chown -R rubyuser:rubyuser $TmpDir" 0
5bae896
        rlRun "rlFetchSrcForInstalled $PACKAGE" 0 "Fetching source package for bundler"
5bae896
        RunAsUser "rpm --define '_topdir $TmpDir' -i $TmpDir/*src.rpm" 0 "Installing the source rpm"
5bae896
        RunAsUser "rpmbuild --nodeps --define '_topdir $TmpDir' -bc $TmpDir/SPECS/*spec" 0 "Configuring build"
5bae896
    rlPhaseEnd
5bae896
5bae896
    rlPhaseStartTest "Run unit tests"
5bae896
        rlRun "cd $TmpDir/BUILD/$PACKAGE-$VERSION/usr/share/gems/gems/bundler-$VERSION"
5bae896
        RunAsUser "tar xzvf $TmpDir/SOURCES/*-specs.tgz" 0 "Unpacking specs into install directory"
5bae896
        RunAsUser "git init ." 0 "Tests require the folder to be a git repo"
5bae896
        RunAsUser "rake spec:deps" 0 "Installing deps"
5bae896
        RunAsUser "rspec spec | tee output.log" 0 "Run unit tests"
5bae896
        rlAssertGrep "examples, 0 failures," output.log
5bae896
    rlPhaseEnd
5bae896
5bae896
    rlPhaseStartCleanup
5bae896
        rlRun "userdel -r $RUNUSER" 0 "Removing rubyuser from the system"
5bae896
        rlRun "popd"
5bae896
        rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
5bae896
    rlPhaseEnd
5bae896
rlJournalPrintText
5bae896
rlJournalEnd