AT_BANNER([RPM install/erase ordering])

AT_SETUP([basic install/erase order 1])
AT_KEYWORDS([install erase order])
RPMDB_INIT

runroot rpmbuild --quiet -bb \
	--define "pkg one" \
	--define "reqs deptest-two" \
	/data/SPECS/deptest.spec
runroot rpmbuild --quiet -bb \
	--define "pkg two" \
	--define "ord deptest-three" \
	/data/SPECS/deptest.spec
runroot rpmbuild --quiet -bb \
	--define "pkg three" \
	/data/SPECS/deptest.spec

RPMTEST_CHECK([
runroot rpm -Uv --justdb \
	/build/RPMS/noarch/deptest-two-1.0-1.noarch.rpm \
	/build/RPMS/noarch/deptest-three-1.0-1.noarch.rpm \
	/build/RPMS/noarch/deptest-one-1.0-1.noarch.rpm
],
[0],
[Verifying packages...
Preparing packages...
deptest-three-1.0-1.noarch
deptest-two-1.0-1.noarch
deptest-one-1.0-1.noarch
],
[])

RPMTEST_CHECK([
runroot rpm -ev --justdb \
        deptest-three \
	deptest-one \
	deptest-two
],
[0],
[Preparing packages...
deptest-one-1.0-1.noarch
deptest-two-1.0-1.noarch
deptest-three-1.0-1.noarch
],
[])
RPMTEST_CLEANUP

# same as above but with mixed weak dependencies
AT_SETUP([basic install/erase order 2])
AT_KEYWORDS([install erase order])
RPMDB_INIT

runroot rpmbuild --quiet -bb \
	--define "pkg one" \
	--define "reqs deptest-two" \
	/data/SPECS/deptest.spec
runroot rpmbuild --quiet -bb \
	--define "pkg two" \
	--define "sugs deptest-three" \
	/data/SPECS/deptest.spec
runroot rpmbuild --quiet -bb \
	--define "pkg three" \
	/data/SPECS/deptest.spec

RPMTEST_CHECK([
runroot rpm -Uv --justdb \
	/build/RPMS/noarch/deptest-two-1.0-1.noarch.rpm \
	/build/RPMS/noarch/deptest-three-1.0-1.noarch.rpm \
	/build/RPMS/noarch/deptest-one-1.0-1.noarch.rpm
],
[0],
[Verifying packages...
Preparing packages...
deptest-two-1.0-1.noarch
deptest-one-1.0-1.noarch
deptest-three-1.0-1.noarch
],
[])

RPMTEST_CHECK([
runroot rpm -ev --justdb \
	deptest-two \
        deptest-three \
	deptest-one
],
[0],
[Preparing packages...
deptest-one-1.0-1.noarch
deptest-two-1.0-1.noarch
deptest-three-1.0-1.noarch
],
[])
RPMTEST_CLEANUP

# same as above but with all weak reverse dependencies
# these are all considered meta by ordering, so order is simply reverse
# of the cli
AT_SETUP([basic install/erase order 3])
AT_KEYWORDS([install erase order])
RPMDB_INIT

runroot rpmbuild --quiet -bb \
	--define "pkg one" \
	/data/SPECS/deptest.spec
runroot rpmbuild --quiet -bb \
	--define "pkg two" \
	--define "sups deptest-one" \
	/data/SPECS/deptest.spec
runroot rpmbuild --quiet -bb \
	--define "pkg three" \
	--define "ens deptest-two" \
	/data/SPECS/deptest.spec

RPMTEST_CHECK([
runroot rpm -Uv --justdb \
	/build/RPMS/noarch/deptest-two-1.0-1.noarch.rpm \
	/build/RPMS/noarch/deptest-three-1.0-1.noarch.rpm \
	/build/RPMS/noarch/deptest-one-1.0-1.noarch.rpm
],
[0],
[Verifying packages...
Preparing packages...
deptest-one-1.0-1.noarch
deptest-three-1.0-1.noarch
deptest-two-1.0-1.noarch
],
[])

RPMTEST_CHECK([
runroot rpm -ev --justdb \
        deptest-three \
	deptest-one \
	deptest-two
],
[0],
[Preparing packages...
deptest-two-1.0-1.noarch
deptest-one-1.0-1.noarch
deptest-three-1.0-1.noarch
],
[])
RPMTEST_CLEANUP
