From 58cf2c940358833b504ec9e8b2d79835bd1e65ad Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 10 Feb 2016 11:42:57 +0100 Subject: [PATCH] tests: Add test coverage for rpm-ostree container --- Makefile-tests.am | 4 ++ src/libpriv/rpmostree-core.c | 8 +++- tests/libtest.sh | 16 ++++++- tests/test-ucontainer.sh | 84 ++++++++++++++++++++++++++++++++++++ 4 files changed, 109 insertions(+), 3 deletions(-) create mode 100755 tests/test-ucontainer.sh diff --git a/Makefile-tests.am b/Makefile-tests.am index bb9a7b36..6fffdfa4 100644 --- a/Makefile-tests.am +++ b/Makefile-tests.am @@ -1,5 +1,7 @@ include $(top_srcdir)/buildutil/glib-tap.mk +AM_TESTS_ENVIRONMENT = UNINSTALLEDTESTS=1 builddir=$(abs_builddir) + CLEANFILES += \ tests/setup-session.sh \ tests/compose/yum/empty tests/compose/yum/repodata/repomd.xml \ @@ -57,6 +59,8 @@ test_programs = \ tests/jsonutil \ $(NULL) +test_scripts = tests/test-ucontainer.sh + installed_test_PROGRAMS += dbus-run-session dbus_run_session_SOURCES = tests/dbus-run-session.c diff --git a/src/libpriv/rpmostree-core.c b/src/libpriv/rpmostree-core.c index 920f8f6c..80ec8569 100644 --- a/src/libpriv/rpmostree-core.c +++ b/src/libpriv/rpmostree-core.c @@ -267,11 +267,17 @@ add_canonicalized_string_array (GVariantBuilder *builder, g_variant_builder_add (builder, "{sv}", notfound_key, g_variant_new_boolean (TRUE)); return TRUE; } - else + else if (temp_error) { g_propagate_error (error, g_steal_pointer (&temp_error)); return FALSE; } + else + { + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, + "Key %s is empty", key); + return FALSE; + } } for (iter = input; iter && *iter; iter++) diff --git a/tests/libtest.sh b/tests/libtest.sh index 7b1cb387..c5053b28 100644 --- a/tests/libtest.sh +++ b/tests/libtest.sh @@ -18,6 +18,18 @@ # Boston, MA 02111-1307, USA. SRCDIR=$(dirname $0) +_cleanup_tmpdir () { + if test -f ${test_tmpdir}.test; then + rm ${test_tmpdir} -rf + fi +} +if test -n "${UNINSTALLEDTESTS:-}"; then + test_tmpdir=$(mktemp -d test.XXXXXX) + touch ${test_tmpdir}/.test + trap _cleanup_tmpdir EXIT + cd ${test_tmpdir} + export PATH=${builddir}:${PATH} +fi test_tmpdir=$(pwd) export G_DEBUG=fatal-warnings @@ -30,11 +42,11 @@ export TEST_GPG_KEYID="472CDAFA" export TEST_GPG_KEYHOME=${SRCDIR}/gpghome export OSTREE_GPG_HOME=${TEST_GPG_KEYHOME}/trusted -if test -n "${OT_TESTS_DEBUG}"; then +if test -n "${OT_TESTS_DEBUG:-}"; then set -x fi -if test -n "$OT_TESTS_VALGRIND"; then +if test -n "${OT_TESTS_VALGRIND:-}"; then CMD_PREFIX="env G_SLICE=always-malloc valgrind -q --leak-check=full --num-callers=30 --suppressions=${SRCDIR}/ostree-valgrind.supp" fi diff --git a/tests/test-ucontainer.sh b/tests/test-ucontainer.sh new file mode 100755 index 00000000..b8ce7abb --- /dev/null +++ b/tests/test-ucontainer.sh @@ -0,0 +1,84 @@ +#!/bin/bash +# +# Copyright (C) 2016 Colin Walters +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library 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 +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + +set -euo pipefail + +. $(dirname $0)/libtest.sh + +echo "1..2" + +rpm-ostree container init +if test -d ${SRCDIR}/compose; then + composedatadir=${SRCDIR}/compose +else + composedatadir=${SRCDIR} +fi +cp ${composedatadir}/test-repo.repo rpmmd.repos.d + +cat >empty.conf <nobranch.conf <err.txt; then + assert_not_reached "nobranch.conf" +fi + +cat >nopackages.conf <err.txt; then + assert_not_reached "nopackages.conf" +fi + +cat >norepos.conf <err.txt; then + assert_not_reached "norepos.conf" +fi + +cat >notfoundpackage.conf <err.txt; then + assert_not_reached "notfound.conf" +fi + +echo "ok error conditions"