#!/bin/bash
set -eu

TESTDIR=$(readlink -f $(dirname $0))
. $TESTDIR/framework

setupenvironment

buildpackage 'conflicting-package-distupgrade'
buildpackage 'conflicting-package-one'
buildpackage 'conflicting-package-two'
buildpackage 'missing-dependency'
buildpackage 'simple-package-new'
buildpackage 'simple-package-noarch'
buildpackage 'simple-package'
buildpackage 'simple-package-update'
buildpackage 'simple-virtual'

generaterepository_and_switch_sources "$TMPWORKINGDIRECTORY/usr/src/RPM/RPMS"

testsuccess aptget update

pkgnames_with_gpgpubkey=()
for (( i = 0; i < APT_TEST_GPGPUBKEY > 0; ++i )); do
    id="$(tr [:upper:] [:lower:] <"$APT_TEST_INTERMEDIATES"/gpg-pubkey/"$i"/id)"
    id32bit="$(echo -n "$id" | tail -c 8)"
    time="$(<"$APT_TEST_INTERMEDIATES"/gpg-pubkey/"$i"/time)"
    printf -v time_hex '%x' "$time"
    time_hex="${time_hex#0x}"
    evrdt_re="$id32bit-$time_hex@$time"
    pkgnames_with_gpgpubkey=(
	"${pkgnames_with_gpgpubkey[@]}"
	"gpg-pubkey#$evrdt_re"
	"gpg\(Some One <$i@example\.com>\)"
	"gpg\($id32bit\)"
    )
done
readonly -a pkgnames_with_gpgpubkey

testpartsexhaust "${pkgnames_with_gpgpubkey[@]}" \
'conflicting-package-two
no-such-package
simple-virtual
simple-package-noarch
virtual\(dummy\)
simple-package-new
missing-dependency
simple-package
conflicting-package-one' \
-- aptcache pkgnames
