#!/bin/bash
set -eu

TESTDIR=$(readlink -f $(dirname $0))

case "$APT_TEST_METHOD" in
	cdrom*)
		echo 'SKIP (not ready for apt-cdrom, because it fetches the lists earlier)' >&2
		exit 0
		;;
esac

. $TESTDIR/framework-without-repo
prereq $TESTDIR/test-apt-update-simple

# Fake pkglist (only noarch, since a noarch pkg is definitely present).
#
# (For faking individual cksums, see other tests,
# like test-apt-update-verifies-CKSUM-of-pkglist-index.)
fake_repo_noarch_pkglist \
    sed -Ee 's:nobody:oooody:'

# Cksum verification should pass actually!
# Because the old fetched pkglist matches the cksum
# (we haven't changed it in the release file).
# And it is cached uncompressed, so the size matches, too.
# FIXME: The only exception to this behavior is copy method for some reason.

case "$APT_TEST_METHOD" in
	copy)
	    testregexmatch '.*(Checksum|BLAKE2b) mismatch of index file.*' \
			   aptget update
	    ;;
	*)
	    testsuccess aptget update
	    ;;
esac
testsuccess aptcache show simple-package
testsuccess aptcache show simple-package-noarch
testfailure aptcache show nosuchpkg
