#    rpmgeneral.at: Some very basic checks
#
#    Copyright (C) 2007  Ralf Corsépius <corsepiu@fedoraproject.org>
#
#    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, write to the Free Software
#    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

AT_BANNER([Basic tests])

# ------------------------------
AT_SETUP([rpm --version])
AT_KEYWORDS([basic])
RPMTEST_CHECK([runroot rpm --version],[0],
[RPM version AT_PACKAGE_VERSION
])
RPMTEST_CLEANUP

# ------------------------------
AT_SETUP([rpmbuild --version])
AT_KEYWORDS([basic])
RPMTEST_CHECK([runroot rpmbuild --version],[0],
[RPM version AT_PACKAGE_VERSION
])
RPMTEST_CLEANUP

AT_SETUP([rpm invalid option])
AT_KEYWORDS([basic])
RPMTEST_CHECK([runroot rpm --badopt],
[1],
[],
[rpm: --badopt: unknown option
])
RPMTEST_CLEANUP

# Check that libtool versioning matches expectations, it's easy to screw up.
AT_SETUP([rpm library version])
AT_KEYWORDS([basic])
AT_SKIP_IF(test -f "${RPMTEST}/${RPMLIBDIR}/librpm.a")
RPMTEST_CHECK_PINNED([rpmlibver])
RPMTEST_CLEANUP

# ------------------------------
AT_SETUP([rpm --showrc])
AT_KEYWORDS([basic])
RPMTEST_CHECK([runroot rpm --showrc],[0],
[ignore])
RPMTEST_CLEANUP

# ------------------------------
# Check rpm --querytags
# * Some versions of rpm append extraneous whitespaces
AT_SETUP([rpm --querytags])
AT_KEYWORDS([basic])
RPMTEST_CHECK([runroot rpm --querytags],[0],
[ARCH
ARCHIVESIZE
ARCHSUFFIX
BASENAMES
BUGURL
BUILDARCHS
BUILDHOST
BUILDTIME
C
CHANGELOGNAME
CHANGELOGTEXT
CHANGELOGTIME
CLASSDICT
CONFLICTFLAGS
CONFLICTNAME
CONFLICTNEVRS
CONFLICTS
CONFLICTVERSION
COOKIE
DBINSTANCE
DEPENDSDICT
DESCRIPTION
DIRINDEXES
DIRNAMES
DISTRIBUTION
DISTTAG
DISTURL
DSAHEADER
E
ENCODING
ENHANCEFLAGS
ENHANCENAME
ENHANCENEVRS
ENHANCES
ENHANCEVERSION
EPOCH
EPOCHNUM
EVR
EXCLUDEARCH
EXCLUDEOS
EXCLUSIVEARCH
EXCLUSIVEOS
FILECAPS
FILECLASS
FILECOLORS
FILECONTEXTS
FILEDEPENDSN
FILEDEPENDSX
FILEDEVICES
FILEDIGESTALGO
FILEDIGESTS
FILEFLAGS
FILEGROUPNAME
FILEINODES
FILELANGS
FILELINKTOS
FILEMD5S
FILEMODES
FILEMTIMES
FILENAMES
FILENLINKS
FILEPROVIDE
FILERDEVS
FILEREQUIRE
FILESIGNATURELENGTH
FILESIGNATURES
FILESIZES
FILESTATES
FILETRIGGERCONDS
FILETRIGGERFLAGS
FILETRIGGERINDEX
FILETRIGGERNAME
FILETRIGGERPRIORITIES
FILETRIGGERSCRIPTFLAGS
FILETRIGGERSCRIPTPROG
FILETRIGGERSCRIPTS
FILETRIGGERTYPE
FILETRIGGERVERSION
FILEUSERNAME
FILEVERIFYFLAGS
FSCONTEXTS
GIF
GROUP
HDRID
HEADERCOLOR
HEADERI18NTABLE
HEADERIMAGE
HEADERIMMUTABLE
HEADERREGIONS
HEADERSIGNATURES
ICON
INSTALLCOLOR
INSTALLTID
INSTALLTIME
INSTFILENAMES
INSTPREFIXES
LICENSE
LONGARCHIVESIZE
LONGFILESIZES
LONGSIGSIZE
LONGSIZE
MODULARITYLABEL
N
NAME
NEVR
NEVRA
NOPATCH
NOSOURCE
NVR
NVRA
O
OBSOLETEFLAGS
OBSOLETENAME
OBSOLETENEVRS
OBSOLETES
OBSOLETEVERSION
OLDENHANCES
OLDENHANCESFLAGS
OLDENHANCESNAME
OLDENHANCESVERSION
OLDFILENAMES
OLDSUGGESTS
OLDSUGGESTSFLAGS
OLDSUGGESTSNAME
OLDSUGGESTSVERSION
OPTFLAGS
ORDERFLAGS
ORDERNAME
ORDERVERSION
ORIGBASENAMES
ORIGDIRINDEXES
ORIGDIRNAMES
ORIGFILENAMES
OS
P
PACKAGER
PATCH
PATCHESFLAGS
PATCHESNAME
PATCHESVERSION
PAYLOADCOMPRESSOR
PAYLOADDIGEST
PAYLOADDIGESTALGO
PAYLOADDIGESTALT
PAYLOADFLAGS
PAYLOADFORMAT
PKGID
PLATFORM
POLICIES
POLICYFLAGS
POLICYNAMES
POLICYTYPES
POLICYTYPESINDEXES
POSTIN
POSTINFLAGS
POSTINPROG
POSTTRANS
POSTTRANSFLAGS
POSTTRANSPROG
POSTUN
POSTUNFLAGS
POSTUNPROG
POSTUNTRANS
POSTUNTRANSFLAGS
POSTUNTRANSPROG
PREFIXES
PREIN
PREINFLAGS
PREINPROG
PRETRANS
PRETRANSFLAGS
PRETRANSPROG
PREUN
PREUNFLAGS
PREUNPROG
PREUNTRANS
PREUNTRANSFLAGS
PREUNTRANSPROG
PROVIDEFLAGS
PROVIDENAME
PROVIDENEVRS
PROVIDES
PROVIDEVERSION
PUBKEYS
R
RECOMMENDFLAGS
RECOMMENDNAME
RECOMMENDNEVRS
RECOMMENDS
RECOMMENDVERSION
RECONTEXTS
RELEASE
REMOVETID
REQUIREFLAGS
REQUIRENAME
REQUIRENEVRS
REQUIRES
REQUIREVERSION
RPMVERSION
RSAHEADER
SHA1HEADER
SHA256HEADER
SIGGPG
SIGMD5
SIGPGP
SIGSIZE
SIZE
SOURCE
SOURCEPACKAGE
SOURCEPKGID
SOURCERPM
SPEC
SUGGESTFLAGS
SUGGESTNAME
SUGGESTNEVRS
SUGGESTS
SUGGESTVERSION
SUMMARY
SUPPLEMENTFLAGS
SUPPLEMENTNAME
SUPPLEMENTNEVRS
SUPPLEMENTS
SUPPLEMENTVERSION
SYSUSERS
TRANSFILETRIGGERCONDS
TRANSFILETRIGGERFLAGS
TRANSFILETRIGGERINDEX
TRANSFILETRIGGERNAME
TRANSFILETRIGGERPRIORITIES
TRANSFILETRIGGERSCRIPTFLAGS
TRANSFILETRIGGERSCRIPTPROG
TRANSFILETRIGGERSCRIPTS
TRANSFILETRIGGERTYPE
TRANSFILETRIGGERVERSION
TRANSLATIONURL
TRIGGERCONDS
TRIGGERFLAGS
TRIGGERINDEX
TRIGGERNAME
TRIGGERSCRIPTFLAGS
TRIGGERSCRIPTPROG
TRIGGERSCRIPTS
TRIGGERTYPE
TRIGGERVERSION
UPSTREAMRELEASES
URL
V
VCS
VENDOR
VERBOSE
VERIFYSCRIPT
VERIFYSCRIPTFLAGS
VERIFYSCRIPTPROG
VERITYSIGNATUREALGO
VERITYSIGNATURES
VERSION
XPM
])
RPMTEST_CLEANUP

AT_SETUP([rpm2cpio])
AT_KEYWORDS([basic])
RPMTEST_CHECK([
runroot_other rpm2cpio /data/RPMS/hello-2.0-1.x86_64.rpm | cpio -t --quiet
],
[0],
[./usr/bin/hello
./usr/share/doc/hello-2.0
./usr/share/doc/hello-2.0/COPYING
./usr/share/doc/hello-2.0/FAQ
./usr/share/doc/hello-2.0/README
])

RPMTEST_CHECK([
runroot_other rpm2cpio /data/SRPMS/hello-1.0-1.src.rpm | cpio -t --quiet
],
[0],
[./hello-1.0.tar.gz
./hello.spec
],
[])
RPMTEST_CLEANUP

AT_SETUP([rpm2archive])
AT_KEYWORDS([basic])
RPMTEST_CHECK([
runroot_other rpm2archive "${RPMTEST}"/data/RPMS/hello-2.0-1.x86_64.rpm | tar tzf -
],
[0],
[./usr/bin/hello
./usr/share/doc/hello-2.0/
./usr/share/doc/hello-2.0/COPYING
./usr/share/doc/hello-2.0/FAQ
./usr/share/doc/hello-2.0/README
],
[])

RPMTEST_CHECK([
runroot_other rpm2archive -n --format=cpio "${RPMTEST}"/data/RPMS/hello-2.0-1.x86_64.rpm | cpio -t --quiet
],
[0],
[./usr/bin/hello
./usr/share/doc/hello-2.0
./usr/share/doc/hello-2.0/COPYING
./usr/share/doc/hello-2.0/FAQ
./usr/share/doc/hello-2.0/README
],
[])
RPMTEST_CHECK([
runroot_other rpm2archive "${RPMTEST}"/data/SRPMS/hello-1.0-1.src.rpm | tar tzf -
],
[0],
[./hello-1.0.tar.gz
./hello.spec
])

RPMTEST_CLEANUP

AT_SETUP([urlhelper missing])
AT_KEYWORDS([urlhelper])
RPMDB_INIT
RPMTEST_CHECK([
# runroot rpm --define "_urlhelper /not/there" --root /srv/test -qp https://example.com/foo-0.1-1.noarch.rpm
runroot rpm --define "_urlhelper /not/there" -qp https://www.example.com/foo-1.0-1.x86_64.rpm
],
[1],
[],
[error: Could not find url helper: "/not/there"
error: open of https://www.example.com/foo-1.0-1.x86_64.rpm failed: No such file or directory
])
RPMTEST_CLEANUP

AT_SETUP([urlhelper fails])
AT_KEYWORDS([urlhelper])
RPMDB_INIT

cat << EOF > "${RPMTEST}"/tmp/fakecurl
#!/bin/sh
sleep 1
>&2 echo \$0: failed to retrieve \$2
exit 7
EOF
chmod a+x "${RPMTEST}"/tmp/fakecurl

RPMTEST_CHECK([
runroot rpm --define "_urlhelper /tmp/fakecurl" --root /srv/test -qp https://example.com/foo-0.1-1.noarch.rpm
],
[1],
[],
[stderr])

RPMTEST_CHECK([
cat stderr | sed 's| /.*rpm-tmp.* https| rpm-tmp https|' | sort
],
[0],
[/tmp/fakecurl: failed to retrieve https://example.com/foo-0.1-1.noarch.rpm
error: Executing url helper "/tmp/fakecurl rpm-tmp https://example.com/foo-0.1-1.noarch.rpm" failed with status 7
error: open of https://example.com/foo-0.1-1.noarch.rpm failed: No such file or directory
],
[])
RPMTEST_CLEANUP
