#!/bin/bash
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Description: Runs upstream test suite
# Author: Miroslav Vadkerti <mvadkert@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2018 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
. /usr/share/beakerlib/beakerlib.sh || { echo "error: Beakerlib is not installed"; exit 1; }
PACKAGE=rubygem-bundler
REQUIRES="rubygem-rspec ruby-devel rubygems-devel gcc"
VERSION=$(rpm -q --qf "%{VERSION}\n" $PACKAGE | tail -1)
RUNUSER="rubyuser"
RunAsUser() {
rlRun "su $RUNUSER -c \"$1\"" $2 "$3"
}
rlJournalStart
rlPhaseStartSetup
rlAssertRpm --all
rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
rlRun "pushd $TmpDir"
rlRun "useradd rubyuser" 0 "Adding user rubyuser to the system"
rlRun "chown -R rubyuser:rubyuser $TmpDir" 0
rlRun "rlFetchSrcForInstalled $PACKAGE" 0 "Fetching source package for bundler"
RunAsUser "rpm --define '_topdir $TmpDir' -i $TmpDir/*src.rpm" 0 "Installing the source rpm"
RunAsUser "rpmbuild --nodeps --define '_topdir $TmpDir' -bc $TmpDir/SPECS/*spec" 0 "Configuring build"
rlPhaseEnd
rlPhaseStartTest "Run unit tests"
rlRun "cd $TmpDir/BUILD/$PACKAGE-$VERSION/usr/share/gems/gems/bundler-$VERSION"
RunAsUser "tar xzvf $TmpDir/SOURCES/*-specs.tgz" 0 "Unpacking specs into install directory"
RunAsUser "git init ." 0 "Tests require the folder to be a git repo"
RunAsUser "rake spec:deps" 0 "Installing deps"
RunAsUser "rspec spec | tee output.log" 0 "Run unit tests"
rlAssertGrep "examples, 0 failures," output.log
rlPhaseEnd
rlPhaseStartCleanup
rlRun "userdel -r $RUNUSER" 0 "Removing rubyuser from the system"
rlRun "popd"
rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
rlPhaseEnd
rlJournalPrintText
rlJournalEnd