From 6a9616f6487af1e77e042563a1ac55384d9899f4 Mon Sep 17 00:00:00 2001 From: Jan Kurik Date: Wed, 7 Jul 2021 20:09:15 +0200 Subject: [PATCH] Added a basic smoke test --- tests/README | 1 + tests/Sanity/smoke/Makefile | 63 ++++++++++++++++++++++++++++++++ tests/Sanity/smoke/PURPOSE | 3 ++ tests/Sanity/smoke/main.fmf | 14 ++++++++ tests/Sanity/smoke/runtest.sh | 68 +++++++++++++++++++++++++++++++++++ 5 files changed, 149 insertions(+) create mode 100644 tests/README create mode 100644 tests/Sanity/smoke/Makefile create mode 100644 tests/Sanity/smoke/PURPOSE create mode 100644 tests/Sanity/smoke/main.fmf create mode 100755 tests/Sanity/smoke/runtest.sh diff --git a/tests/README b/tests/README new file mode 100644 index 0000000..44563dd --- /dev/null +++ b/tests/README @@ -0,0 +1 @@ +This is a repo for tests for python-jsonpointer. diff --git a/tests/Sanity/smoke/Makefile b/tests/Sanity/smoke/Makefile new file mode 100644 index 0000000..6f6da7b --- /dev/null +++ b/tests/Sanity/smoke/Makefile @@ -0,0 +1,63 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Makefile of /tools/python-jsonpointer/Sanity/smoke +# Description: Testing of basic functionality. +# Author: Peter Hostacny , Jan Kuřík +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 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/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +export TEST=/tools/python-jsonpointer/Sanity/smoke +export TESTVERSION=1.0 + +BUILT_FILES= + +FILES=$(METADATA) runtest.sh Makefile PURPOSE + +.PHONY: all install download clean + +run: $(FILES) build + ./runtest.sh + +build: $(BUILT_FILES) + test -x runtest.sh || chmod a+x runtest.sh + +clean: + rm -f *~ $(BUILT_FILES) + + +include /usr/share/rhts/lib/rhts-make.include + +$(METADATA): Makefile + @echo "Owner: Jan Kuřík " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: Testing of basic functionality." >> $(METADATA) + @echo "Type: Sanity" >> $(METADATA) + @echo "TestTime: 5m" >> $(METADATA) + @echo "RunFor: python-jsonpointer" >> $(METADATA) + @echo "Requires: python-jsonpointer python2-jsonpointer python3-jsonpointer" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2+" >> $(METADATA) + @echo "Confidential: no" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + @echo "Releases: -RHEL4 -RHELClient5 -RHELServer5" >> $(METADATA) + + rhts-lint $(METADATA) diff --git a/tests/Sanity/smoke/PURPOSE b/tests/Sanity/smoke/PURPOSE new file mode 100644 index 0000000..c0aad80 --- /dev/null +++ b/tests/Sanity/smoke/PURPOSE @@ -0,0 +1,3 @@ +PURPOSE of /tools/python-jsonpointer/Sanity/smoke +Description: Test of basic functionality. +Author: Jan Kuřík diff --git a/tests/Sanity/smoke/main.fmf b/tests/Sanity/smoke/main.fmf new file mode 100644 index 0000000..482f68a --- /dev/null +++ b/tests/Sanity/smoke/main.fmf @@ -0,0 +1,14 @@ +summary: Testing of basic functionality. +description: '' +contact: Jan Kuřík +component: +- python-jsonpointer +test: ./runtest.sh +framework: beakerlib +recommend: +- python-jsonpointer +- python2-jsonpointer +- python3-jsonpointer +duration: 5m +extra-summary: /tools/python-jsonpointer/Sanity/smoke +extra-task: /tools/python-jsonpointer/Sanity/smoke diff --git a/tests/Sanity/smoke/runtest.sh b/tests/Sanity/smoke/runtest.sh new file mode 100755 index 0000000..58351e4 --- /dev/null +++ b/tests/Sanity/smoke/runtest.sh @@ -0,0 +1,68 @@ +#!/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 , Jan Kuřík +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# 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