socsvn commit: r254205 - soc2013/mattbw/tests/get-details-output
mattbw at FreeBSD.org
mattbw at FreeBSD.org
Sat Jul 6 01:07:30 UTC 2013
Author: mattbw
Date: Sat Jul 6 01:07:30 2013
New Revision: 254205
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=254205
Log:
make test able to handle remote packages; update README
Modified:
soc2013/mattbw/tests/get-details-output/test-pkg.sh
soc2013/mattbw/tests/get-details-output/test.sh
Modified: soc2013/mattbw/tests/get-details-output/test-pkg.sh
==============================================================================
--- soc2013/mattbw/tests/get-details-output/test-pkg.sh Sat Jul 6 00:13:08 2013 (r254204)
+++ soc2013/mattbw/tests/get-details-output/test-pkg.sh Sat Jul 6 01:07:30 2013 (r254205)
@@ -1,17 +1,87 @@
#!/bin/sh
-# Tests pkcon against pkg to make sure the pkg backend works correctly for GetDetails.
+################################################################################
+# Tests pkcon against pkg to make sure the pkg backend works correctly for
+# GetDetails for one package.
#
# More black-box tests should be written later
+#
+# Usage: ./test-pkg [PACKAGE] [PK_REPO]
+# or ./test.sh (runs this over a set of packages)
+#
+# TODO: Specific version/arch requirements in the PackageID
+
+################################################################################
+# Retrieve the arguments.
-if [ $# -eq 1 ]
+if [ $# -gt 0 ]
then
PACKAGE="$1"
else
PACKAGE="pkg"
fi
+# Translate into an evaluation condition so we can use it with a specific
+# rquery repository
+ECOND="-e \"%n==${PACKAGE}\""
-echo "using package ${PACKAGE}"
+if [ $# -gt 1 ]
+then
+ PK_REPO="$2"
+else
+ PK_REPO=""
+fi
+
+################################################################################
+# Convert from PackageKit repository to pkgng repository and query type.
+
+if [ -z "${PK_REPO}" ] # Wildcard (local or any remote repo)
+then
+ TRY_LOCAL=1
+ TRY_REMOTE=1
+ REPO=""
+elif [ "${PK_REPO}" == "installed" ] # Locally installed package
+then
+ TRY_LOCAL=1
+ TRY_REMOTE=0
+else # Specific remote repo
+ TRY_LOCAL=0
+ TRY_REMOTE=1
+ REPO="-r \"${PK_REPO}\""
+fi
+
+FOUND=0
+if [ ${TRY_LOCAL} -gt 0 ]
+then
+ # Does the package exist locally?
+ TEST=`eval pkg query ${ECOND} \"%n\"`
+ if [ -n "${TEST}" ]
+ then
+ FOUND=1
+ TRY_REMOTE=0
+ QTYPE="pkg query"
+ fi
+fi
+if [ ${TRY_REMOTE} -gt 0 ]
+then
+ # Does it exist remotely?
+ TEST="`eval pkg rquery ${REPO} ${ECOND} \"%n\"`"
+ if [ -n "${TEST}" ]
+ then
+ FOUND=1
+ QTYPE="pkg rquery ${REPO}"
+ fi
+fi
+PKGCMD="${QTYPE} ${ECOND}"
+
+# TODO: behave if FOUND is 0
+
+PK_ID="${PACKAGE};;;${PK_REPO}"
+echo "testing with package ${PACKAGE}"
+echo " pkg invocation: ${PKGCMD} ..."
+echo " pkcon invocation: pkcon get-details ${PK_ID}"
+
+################################################################################
+# Infer data not available from a query string but used in PackageKit.
# Get the expected ABI through some invasive inspection of the pkg config dump
ARCH="`pkg -vv | grep ABI | sed 's/ *ABI: *//'`"
@@ -19,31 +89,38 @@
CMD_GETCAT="./getcat"
# Get the PackageKit group of the package
-ORIGIN="`pkg query \"%o\" ${PACKAGE}`"
+ORIGIN="`eval ${PKGCMD} \"%o\"`"
GROUP="`${CMD_GETCAT} ${ORIGIN}`"
-# Get the licences by mashing the `pkg query` licence list and or/and/single identifier
-# into one "licence or licence or licence" string.
+# Get the licences by mashing the `pkg query` licence list and or/and/single
+# identifier into one "licence or licence or licence" string.
LICENSE=`\
- pkg query "%L %l" "${PACKAGE}" | # "licence or\nlicence or\n"
- tr "\n" " " | # "licence or licence or ", note space
- sed 's/ *[^ ]* *$//'` # "licence or licence"
+ eval ${PKGCMD} \"%L %l\" | # "GPL or\nBSD or\n"
+ tr "\n" " " | # "GPL or BSD or ",
+ sed 's/ *[^ ]* *$//'` # "GPL or BSD"
+
+################################################################################
+# Build and run the queries.
# Build a format string for the query that mocks up a pkcon GetDetails result
-FMT="Package description
+# This has to be done in such an ugly way because we're eval'ing.
+FMT='Package description
package: %n-%v.${ARCH}
license: ${LICENSE}
group: ${GROUP}
description: %e
size: %sb bytes
- url: %w"
+ url: %w'
# Now run both queries and diff them
PKG_FILE="${PACKAGE}-pkg"
PKCON_FILE="${PACKAGE}-pkcon"
-pkg query "${FMT}" "${PACKAGE}" > "${PKG_FILE}"
-pkcon get-details "${PACKAGE};;;installed" | awk -f "strip_messages.awk" > "${PKCON_FILE}"
+eval ${PKGCMD} \""${FMT}"\" > "${PKG_FILE}"
+pkcon get-details "${PK_ID}" | awk -f "strip_messages.awk" > "${PKCON_FILE}"
+
+################################################################################
+# Diff the results.
DIFF="`diff -rupN \"${PACKAGE}-pkg\" \"${PACKAGE}-pkcon\"`"
if [ -n "${DIFF}" ]
Modified: soc2013/mattbw/tests/get-details-output/test.sh
==============================================================================
--- soc2013/mattbw/tests/get-details-output/test.sh Sat Jul 6 00:13:08 2013 (r254204)
+++ soc2013/mattbw/tests/get-details-output/test.sh Sat Jul 6 01:07:30 2013 (r254205)
@@ -4,7 +4,7 @@
while read LINE
do
- ./test-pkg.sh "${LINE}"
+ ./test-pkg.sh ${LINE}
if [ $? -ne 0 ]
then
echo "tests failed"
More information about the svn-soc-all
mailing list