Blame run-basic-rails-application/runtest.sh

a4cdc02
#!/bin/bash
a4cdc02
# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
a4cdc02
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a4cdc02
#
a4cdc02
#   runtest.sh of /CoreOS/rubygem-rails/run-basic-rails-application
a4cdc02
#   Description: Test creates new rails application and runs it
a4cdc02
#   Author: Iveta Senfeldova <isenfeld@redhat.com>
a4cdc02
#
a4cdc02
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a4cdc02
#
a4cdc02
#   Copyright (c) 2012 Red Hat, Inc. All rights reserved.
a4cdc02
#
a4cdc02
#   This copyrighted material is made available to anyone wishing
a4cdc02
#   to use, modify, copy, or redistribute it subject to the terms
a4cdc02
#   and conditions of the GNU General Public License version 2.
a4cdc02
#
a4cdc02
#   This program is distributed in the hope that it will be
a4cdc02
#   useful, but WITHOUT ANY WARRANTY; without even the implied
a4cdc02
#   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
a4cdc02
#   PURPOSE. See the GNU General Public License for more details.
a4cdc02
#
a4cdc02
#   You should have received a copy of the GNU General Public
a4cdc02
#   License along with this program; if not, write to the Free
a4cdc02
#   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
a4cdc02
#   Boston, MA 02110-1301, USA.
a4cdc02
#
a4cdc02
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a4cdc02
a4cdc02
# Include Beaker environment
a4cdc02
[ -e /usr/bin/rhts-environment.sh ] && . /usr/bin/rhts-environment.sh
1511ce4
. /usr/share/beakerlib/beakerlib.sh
a4cdc02
1511ce4
PACKAGES=${PACKAGES:-ruby rubygems rubypick}
a4cdc02
REQUIRES=${REQUIRES:-}
a4cdc02
RUBY=${RUBY:-ruby}
a4cdc02
RAILS=0
a4cdc02
bundle=""
a4cdc02
ARCH=$(uname -m)
a4cdc02
RAILSVER=""
a4cdc02
a4cdc02
# version of Ruby on RHEL7 needs older version of rails
a4cdc02
if rlIsRHEL 7; then RAILSVER="-v 4.2.7"; NOKOVER="-v 1.6.8"; fi
a4cdc02
a4cdc02
rlJournalStart
a4cdc02
    rlPhaseStartSetup
a4cdc02
        rlAssertRpm --all
a4cdc02
        rlAssertBinaryOrigin $RUBY
a4cdc02
        rlAssertBinaryOrigin "gem"
a4cdc02
        rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
a4cdc02
        rlRun "pushd $TmpDir"
1511ce4
1511ce4
        # install rails and nokogiri from gem if not found in installation
1511ce4
        if ! gem list "^rails *$" -i
a4cdc02
        then
a4cdc02
            # nokogiri gem installed with rails needs to use system libraries
a4cdc02
            # on arm and ppcle otherwise it fails with bundled libraries
a4cdc02
            if [ "x$ARCH" = "xaarch64" ] || [ "x$ARCH" = "xppc64le" ]
a4cdc02
            then
a4cdc02
                export NOKOGIRI_USE_SYSTEM_LIBRARIES=yes
a4cdc02
            fi
a4cdc02
            rlRun "gem install nokogiri $NOKOVER --no-document" 0 "Installing nokogiri $NOKOVER without documentation"
a4cdc02
            rlRun "gem install rails $RAILSVER --no-document" 0 "Installing rails $RAILSVER without documentation"
a4cdc02
            RAILS=1
a4cdc02
        fi
a4cdc02
    rlPhaseEnd
a4cdc02
a4cdc02
    rlPhaseStartTest
a4cdc02
        rlRun "rails new app | tee bundle.log" 0 "Creating new rails application"
a4cdc02
        [ ! -z "$COLLECTIONS" ] && rlAssertGrep "bundle install --local" bundle.log || rlAssertNotGrep "bundle install --local" bundle.log
a4cdc02
        rlRun "pushd app/"
a4cdc02
        rlAssertExists "app"
a4cdc02
a4cdc02
        if [[ ! "$COLLECTIONS" =~ "rh-ror50" ]]
a4cdc02
        then
a4cdc02
            rlRun "echo \"gem 'therubyracer'\" >> Gemfile" 0 "Adding therubyracer gem into Gemfile"
057642b
            rlRun "bundle install"
a4cdc02
        fi
a4cdc02
1511ce4
        if [ -z "$COLLECTIONS" ] && rlIsRHEL '<=7'
a4cdc02
        then
a4cdc02
            rlRun "echo \"gem 'nokogiri', '1.6.8'\" >> Gemfile" 0 "Adding nokogiri gem into Gemfile"
a4cdc02
            sed -i "s/gem 'spring'/#gem 'spring'/" Gemfile
a4cdc02
            rlRun "gem pristine nokogiri" 0 "Restore installed nokogiri to pristine condition"
a4cdc02
            rlRun "bundle config build.nokogiri --use-system-libraries" 0 "Build nokogiri with system libraries"
057642b
            rlRun "bundle install"
a4cdc02
        fi
a4cdc02
        rlRun "netstat -tulpn | grep 3000" 1 "Check if port 3000 isn't engaged"
a4cdc02
        rlRun "rails server &" 0 "Running rails server"
a4cdc02
        sleep 10
a4cdc02
        rlRun "wget http://0.0.0.0:3000" 0 "Wgetting running rails application"
057642b
        rlRun "pkill ruby" 0 "Killing rails server"
a4cdc02
    rlPhaseEnd
a4cdc02
a4cdc02
    rlPhaseStartCleanup
a4cdc02
        rlRun "popd; popd"
a4cdc02
        [ $RAILS == 1 ] && rlRun "gem uninstall rails nokogiri minitest -a -I -x" 0 "Removing rails and nokogiri gem"
a4cdc02
        rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
a4cdc02
    rlPhaseEnd
a4cdc02
rlJournalPrintText
a4cdc02
rlJournalEnd