python-jsonpointer/tests/Sanity/smoke/runtest.sh
2021-07-07 20:09:15 +02:00

69 lines
2.5 KiB
Bash
Executable File

#!/bin/bash
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# runtest.sh of /tools/python-jsonpointer/Sanity/smoke
# Description: Testing of basic functionality.
# Author: Peter Hostacny <phostacn@redhat.com>, Jan Kuřík <jkurik@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2015-2021 Red Hat, Inc.
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 2 of
# the License, or (at your option) any later version.
#
# 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, see http://www.gnu.org/licenses/.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include Beaker environment
. /usr/share/beakerlib/beakerlib.sh || exit 1
rlJournalStart
rlPhaseStartSetup
if rpm -q --quiet python-jsonpointer; then
PACKAGE="python-jsonpointer"
elif rpm -q --quiet python3-jsonpointer; then
PACKAGE="python3-jsonpointer"
else
rlDie "No python's jsonpointer package is installed"
fi
rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
rlRun "pushd $TmpDir"
rlRun "echo '{ \"a\": [1, 2, 3] }' > a.json" 0 "Creating test-file."
rlRun "echo '{ \"a\": {\"b\": [1, 3, 4]}, \"b\": 1 }' > b.json" 0 "Creating test-file."
rlRun "echo '\"/a\"' > ptr.json" 0 "Creating test-file."
# Setting of pipefail shell option
set -o pipefail
rlPhaseEnd
rlPhaseStartTest
if rlTestVersion $(rpm -q --qf '%{version}' ${PACKAGE}) '<' 2; then
__ptr="ptr.json"
else
__ptr=$(tr -d '"' < ptr.json)
fi
rlRun -s "jsonpointer '${__ptr}' a.json b.json" 0 \
"Testing of jsonpointer commandline utility - simple run."
rlAssertGrep "[1, 2, 3]" "${rlRun_LOG}"
rlAssertGrep "{\"b\": \[1, 3, 4\]}" "${rlRun_LOG}"
rlPhaseEnd
rlPhaseStartCleanup
rlRun "popd"
rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
rlPhaseEnd
rlJournalPrintText
rlJournalEnd