#    rpmvercmp.at: rpm config file behavior tests

AT_BANNER([RPM config file behavior])

# Install over existing config file
AT_SETUP([install config on existiting file])
AT_KEYWORDS([install])
AT_CHECK([
RPMDB_CLEAR
RPMDB_INIT
cf="${RPMTEST}"/etc/my.conf
rm -rf "${cf}" "${cf}".rpm*
rm -rf "${TOPDIR}"

runroot rpmbuild --quiet -bb \
        --define "ver 1.0" \
	--define "filedata foo" \
          /data/SPECS/configtest.spec

echo "otherstuff" > "${cf}"
runroot rpm -U "${TOPDIR}"/RPMS/noarch/configtest-1.0-1.noarch.rpm
cat "${cf}"
runroot rpm -e configtest
cat "${cf}.rpmorig"
],
[0],
[foo
otherstuff
],
[warning: /etc/my.conf saved as /etc/my.conf.rpmorig]
)
AT_CLEANUP

# Install over existing config file
AT_SETUP([install config(noreplace) on existiting file])
AT_KEYWORDS([install])
AT_CHECK([
RPMDB_CLEAR
RPMDB_INIT
cf="${RPMTEST}"/etc/my.conf
rm -rf "${cf}" "${cf}".rpm*
rm -rf "${TOPDIR}"

runroot rpmbuild --quiet -bb \
        --define "ver 1.0" \
	--define "filedata foo" \
          /data/SPECS/configtest.spec

echo "otherstuff" > "${cf}"
runroot rpm -U "${TOPDIR}"/RPMS/noarch/configtest-1.0-1.noarch.rpm
cat "${cf}"
runroot rpm -e configtest
cat "${cf}.rpmorig"
],
[0],
[foo
otherstuff
],
[warning: /etc/my.conf saved as /etc/my.conf.rpmorig]
)
AT_CLEANUP

# Install over existing identical config file, no backup needed
AT_SETUP([install config on existiting identical file])
AT_KEYWORDS([install])
AT_CHECK([
RPMDB_CLEAR
RPMDB_INIT
cf="${RPMTEST}"/etc/my.conf
rm -rf "${cf}" "${cf}".rpm*
rm -rf "${TOPDIR}"

runroot rpmbuild --quiet -bb \
        --define "ver 1.0" \
	--define "filedata foo" \
          /data/SPECS/configtest.spec

echo "foo" > "${cf}"
runroot rpm -U "${TOPDIR}"/RPMS/noarch/configtest-1.0-1.noarch.rpm
cat "${cf}"
runroot rpm -e configtest
test ! -f "${cf}"
],
[0],
[foo
],
[])
AT_CLEANUP

# Erase unmodified config file, no backup here
AT_SETUP([erase unchanged config])
AT_KEYWORDS([install])
AT_CHECK([
RPMDB_CLEAR
RPMDB_INIT
cf="${RPMTEST}"/etc/my.conf
rm -rf "${cf}" "${cf}".rpm*
rm -rf "${TOPDIR}"

runroot rpmbuild --quiet -bb \
        --define "ver 1.0" \
	--define "filedata foo" \
          /data/SPECS/configtest.spec

runroot rpm -U "${TOPDIR}"/RPMS/noarch/configtest-1.0-1.noarch.rpm
cat "${cf}"
runroot rpm -e configtest
test ! -f "${cf}"
],
[0],
[foo
],
[])
AT_CLEANUP

# Erase modified config file
AT_SETUP([erase changed config])
AT_KEYWORDS([install])
AT_CHECK([
RPMDB_CLEAR
RPMDB_INIT
cf="${RPMTEST}"/etc/my.conf
rm -rf "${cf}" "${cf}".rpm*
rm -rf "${TOPDIR}"

runroot rpmbuild --quiet -bb \
        --define "ver 1.0" \
	--define "filedata foo" \
          /data/SPECS/configtest.spec

runroot rpm -U "${TOPDIR}"/RPMS/noarch/configtest-1.0-1.noarch.rpm
cat "${cf}"
echo "otherstuff" > "${cf}"
runroot rpm -e configtest
cat "${cf}.rpmsave"
test ! -f "${cf}"
],
[0],
[foo
otherstuff
],
[warning: /etc/my.conf saved as /etc/my.conf.rpmsave]
)
AT_CLEANUP

# Erase modified config(noreplace) file
AT_SETUP([erase changed config(noreplace)])
AT_KEYWORDS([install])
AT_CHECK([
RPMDB_CLEAR
RPMDB_INIT
cf="${RPMTEST}"/etc/my.conf
rm -rf "${cf}" "${cf}".rpm*
rm -rf "${TOPDIR}"

runroot rpmbuild --quiet -bb \
        --define "ver 1.0" \
	--define "filedata foo" \
	--define "noreplace 1" \
          /data/SPECS/configtest.spec

runroot rpm -U "${TOPDIR}"/RPMS/noarch/configtest-1.0-1.noarch.rpm
cat "${cf}"
echo "otherstuff" > "${cf}"
runroot rpm -e configtest
cat "${cf}.rpmsave"
test ! -f "${cf}"
],
[0],
[foo
otherstuff
],
[warning: /etc/my.conf saved as /etc/my.conf.rpmsave]
)
AT_CLEANUP

# ------------------------------
# (Build and) upgrade package with config file, no backup here
AT_SETUP([upgrade unchanged config])
AT_KEYWORDS([install])
AT_CHECK([
RPMDB_CLEAR
RPMDB_INIT
cf="${RPMTEST}"/etc/my.conf
rm -rf "${cf}" "${cf}".rpm*
rm -rf "${TOPDIR}"

for v in "1.0" "2.0"; do
    runroot rpmbuild --quiet -bb \
        --define "ver $v" \
	--define "filedata foo" \
          /data/SPECS/configtest.spec
done

runroot rpm -U "${TOPDIR}"/RPMS/noarch/configtest-1.0-1.noarch.rpm
cat "${cf}"
runroot rpm -U "${TOPDIR}"/RPMS/noarch/configtest-2.0-1.noarch.rpm
cat "${cf}"
],
[0],
[foo
foo
],
[])
AT_CLEANUP
#
# ------------------------------
# Upgrade package with locally modified config file, unchanged in pkg
AT_SETUP([upgrade modified config])
AT_KEYWORDS([install])
AT_CHECK([
RPMDB_CLEAR
RPMDB_INIT
cf="${RPMTEST}"/etc/my.conf
rm -rf "${cf}" "${cf}".rpm*
rm -rf "${TOPDIR}"

for v in "1.0" "2.0"; do
    runroot rpmbuild --quiet -bb \
        --define "ver $v" \
	--define "filedata foo" \
          /data/SPECS/configtest.spec
done

runroot rpm -U "${TOPDIR}"/RPMS/noarch/configtest-1.0-1.noarch.rpm
cat "${cf}"
echo "otherstuff" > "${cf}"
cat "${cf}"
runroot rpm -U "${TOPDIR}"/RPMS/noarch/configtest-2.0-1.noarch.rpm
cat "${cf}"
],
[0],
[foo
otherstuff
otherstuff
],
[])
AT_CLEANUP

# ------------------------------
# Upgrade package with unmodified config file, changed in pkg
AT_SETUP([upgrade changing config])
AT_KEYWORDS([install])
AT_CHECK([
RPMDB_CLEAR
RPMDB_INIT
cf="${RPMTEST}"/etc/my.conf
rm -rf "${cf}" "${cf}".rpm*
rm -rf "${TOPDIR}"

for v in "1.0" "2.0"; do
    runroot rpmbuild --quiet -bb \
        --define "ver $v" \
	--define "filedata foo-$v" \
          /data/SPECS/configtest.spec
done

runroot rpm -U "${TOPDIR}"/RPMS/noarch/configtest-1.0-1.noarch.rpm
cat "${cf}"
runroot rpm -U "${TOPDIR}"/RPMS/noarch/configtest-2.0-1.noarch.rpm
cat "${cf}"
],
[0],
[foo-1.0
foo-2.0
],
[])
AT_CLEANUP

# ------------------------------
# Upgrade package with locally modified config file, changed in pkg
AT_SETUP([upgrade changing, modified config 1])
AT_KEYWORDS([install])
AT_CHECK([
RPMDB_CLEAR
RPMDB_INIT
cf="${RPMTEST}"/etc/my.conf
rm -rf "${cf}" "${cf}".rpm*
rm -rf "${TOPDIR}"

for v in "1.0" "2.0"; do
    runroot rpmbuild --quiet -bb \
        --define "ver $v" \
	--define "filedata foo-$v" \
          /data/SPECS/configtest.spec
done

runroot rpm -U "${TOPDIR}"/RPMS/noarch/configtest-1.0-1.noarch.rpm
cat "${cf}"
echo "otherstuff" > "${RPMTEST}"/etc/my.conf
cat "${cf}"
runroot rpm -U "${TOPDIR}"/RPMS/noarch/configtest-2.0-1.noarch.rpm
cat "${cf}"
cat "${cf}.rpmsave"
],
[0],
[foo-1.0
otherstuff
foo-2.0
otherstuff
],
[warning: /etc/my.conf saved as /etc/my.conf.rpmsave]
)
AT_CLEANUP

# ------------------------------
# Modified config file matches the content from new package.
AT_SETUP([upgrade changing, modified config 2])
AT_KEYWORDS([install])
AT_CHECK([
RPMDB_CLEAR
RPMDB_INIT
cf="${RPMTEST}"/etc/my.conf
rm -rf "${cf}" "${cf}".rpm*
rm -rf "${TOPDIR}"

for v in "1.0" "2.0"; do
    runroot rpmbuild --quiet -bb \
        --define "ver $v" \
	--define "filedata foo-$v" \
          /data/SPECS/configtest.spec
done

runroot rpm -U "${TOPDIR}"/RPMS/noarch/configtest-1.0-1.noarch.rpm
cat "${cf}"
echo "foo-2.0" > "${RPMTEST}"/etc/my.conf
cat "${cf}"
runroot rpm -U "${TOPDIR}"/RPMS/noarch/configtest-2.0-1.noarch.rpm
cat "${cf}"
],
[0],
[foo-1.0
foo-2.0
foo-2.0
],
[])
AT_CLEANUP

# config(noreplace) variants of the same cases.
#
# ------------------------------
# (Build and) upgrade package with config file, no backup here
AT_SETUP([upgrade unchanged config(noreplace)])
AT_KEYWORDS([install])
AT_CHECK([
RPMDB_CLEAR
RPMDB_INIT
cf="${RPMTEST}"/etc/my.conf
rm -rf "${cf}" "${cf}".rpm*
rm -rf "${TOPDIR}"

for v in "1.0" "2.0"; do
    runroot rpmbuild --quiet -bb \
        --define "ver $v" \
	--define "filedata foo" \
	--define "noreplace 1" \
          /data/SPECS/configtest.spec
done

runroot rpm -U "${TOPDIR}"/RPMS/noarch/configtest-1.0-1.noarch.rpm
cat "${cf}"
runroot rpm -U "${TOPDIR}"/RPMS/noarch/configtest-2.0-1.noarch.rpm
cat "${cf}"
],
[0],
[foo
foo
],
[])
AT_CLEANUP

#
# ------------------------------
# Upgrade package with locally modified config file, unchanged in pkg
AT_SETUP([upgrade modified config(noreplace)])
AT_KEYWORDS([install])
AT_CHECK([
RPMDB_CLEAR
RPMDB_INIT
cf="${RPMTEST}"/etc/my.conf
rm -rf "${cf}" "${cf}".rpm*
rm -rf "${TOPDIR}"

for v in "1.0" "2.0"; do
    runroot rpmbuild --quiet -bb \
        --define "ver $v" \
	--define "filedata foo" \
	--define "noreplace 1" \
          /data/SPECS/configtest.spec
done

runroot rpm -U "${TOPDIR}"/RPMS/noarch/configtest-1.0-1.noarch.rpm
cat "${cf}"
echo "otherstuff" > "${cf}"
cat "${cf}"
runroot rpm -U "${TOPDIR}"/RPMS/noarch/configtest-2.0-1.noarch.rpm
cat "${cf}"
],
[0],
[foo
otherstuff
otherstuff
],
[])
AT_CLEANUP

# ------------------------------
# Upgrade package with unmodified config file, changed in pkg
AT_SETUP([upgrade changing config(noreplace)])
AT_KEYWORDS([install])
AT_CHECK([
RPMDB_CLEAR
RPMDB_INIT
cf="${RPMTEST}"/etc/my.conf
rm -rf "${cf}" "${cf}".rpm*
rm -rf "${TOPDIR}"

for v in "1.0" "2.0"; do
    runroot rpmbuild --quiet -bb \
        --define "ver $v" \
	--define "filedata foo-$v" \
	--define "noreplace 1" \
          /data/SPECS/configtest.spec
done

runroot rpm -U "${TOPDIR}"/RPMS/noarch/configtest-1.0-1.noarch.rpm
cat "${cf}"
runroot rpm -U "${TOPDIR}"/RPMS/noarch/configtest-2.0-1.noarch.rpm
cat "${cf}"
],
[0],
[foo-1.0
foo-2.0
],
[])
AT_CLEANUP

# ------------------------------
# Upgrade package with locally modified config file, changed in pkg
AT_SETUP([upgrade changing, modified config(noreplace) 1])
AT_KEYWORDS([install])
AT_CHECK([
RPMDB_CLEAR
RPMDB_INIT
cf="${RPMTEST}"/etc/my.conf
rm -rf "${cf}" "${cf}".rpm*
rm -rf "${TOPDIR}"

for v in "1.0" "2.0"; do
    runroot rpmbuild --quiet -bb \
        --define "ver $v" \
	--define "filedata foo-$v" \
	--define "noreplace 1" \
          /data/SPECS/configtest.spec
done

runroot rpm -U "${TOPDIR}"/RPMS/noarch/configtest-1.0-1.noarch.rpm
cat "${cf}"
echo "otherstuff" > "${RPMTEST}"/etc/my.conf
cat "${cf}"
runroot rpm -U "${TOPDIR}"/RPMS/noarch/configtest-2.0-1.noarch.rpm
cat "${cf}"
cat "${cf}.rpmnew"
],
[0],
[foo-1.0
otherstuff
otherstuff
foo-2.0
],
[warning: /etc/my.conf created as /etc/my.conf.rpmnew]
)
AT_CLEANUP

# ------------------------------
# Modified config file matches the content from new package.
AT_SETUP([upgrade changing, modified config(noreplace) 2])
AT_KEYWORDS([install])
AT_CHECK([
RPMDB_CLEAR
RPMDB_INIT
cf="${RPMTEST}"/etc/my.conf
rm -rf "${cf}" "${cf}".rpm*
rm -rf "${TOPDIR}"

for v in "1.0" "2.0"; do
    runroot rpmbuild --quiet -bb \
        --define "ver $v" \
	--define "filedata foo-$v" \
	--define "noreplace 1" \
          /data/SPECS/configtest.spec
done

runroot rpm -U "${TOPDIR}"/RPMS/noarch/configtest-1.0-1.noarch.rpm
cat "${cf}"
echo "foo-2.0" > "${RPMTEST}"/etc/my.conf
cat "${cf}"
runroot rpm -U "${TOPDIR}"/RPMS/noarch/configtest-2.0-1.noarch.rpm
cat "${cf}"
],
[0],
[foo-1.0
foo-2.0
foo-2.0
],
[])
AT_CLEANUP

# Shared config file variants of the same cases
# ------------------------------
# (Build and) upgrade package with config file, no backup here
AT_SETUP([upgrade unchanged shared config])
AT_KEYWORDS([install])
AT_CHECK([
RPMDB_CLEAR
RPMDB_INIT
cf="${RPMTEST}"/etc/my.conf
rm -rf "${cf}" "${cf}".rpm*
rm -rf "${TOPDIR}"

for s in "A" "B"; do
    for v in "1.0" "2.0"; do
        runroot rpmbuild --quiet -bb \
            --define "sub $s" \
            --define "ver $v" \
	    --define "filedata foo" \
              /data/SPECS/configtest.spec
    done
done

runroot rpm -U \
    "${TOPDIR}"/RPMS/noarch/configtest-A-1.0-1.noarch.rpm \
    "${TOPDIR}"/RPMS/noarch/configtest-B-1.0-1.noarch.rpm
cat "${cf}"
runroot rpm -U \
    "${TOPDIR}"/RPMS/noarch/configtest-A-2.0-1.noarch.rpm \
    "${TOPDIR}"/RPMS/noarch/configtest-B-2.0-1.noarch.rpm
cat "${cf}"
],
[0],
[foo
foo
],
[])

AT_CLEANUP
#
# ------------------------------
# Upgrade package with locally modified config file, unchanged in pkg
AT_SETUP([upgrade modified shared config])
AT_KEYWORDS([install])
AT_CHECK([
RPMDB_CLEAR
RPMDB_INIT
cf="${RPMTEST}"/etc/my.conf
rm -rf "${cf}" "${cf}".rpm*
rm -rf "${TOPDIR}"

for s in "A" "B"; do
    for v in "1.0" "2.0"; do
        runroot rpmbuild --quiet -bb \
            --define "sub $s" \
            --define "ver $v" \
	    --define "filedata foo" \
              /data/SPECS/configtest.spec
    done
done

runroot rpm -U \
    "${TOPDIR}"/RPMS/noarch/configtest-A-1.0-1.noarch.rpm \
    "${TOPDIR}"/RPMS/noarch/configtest-B-1.0-1.noarch.rpm
cat "${cf}"
echo "otherstuff" > "${cf}"
cat "${cf}"
runroot rpm -U \
    "${TOPDIR}"/RPMS/noarch/configtest-A-2.0-1.noarch.rpm \
    "${TOPDIR}"/RPMS/noarch/configtest-B-2.0-1.noarch.rpm
cat "${cf}"
],
[0],
[foo
otherstuff
otherstuff
],
[])
AT_CLEANUP

# ------------------------------
# Upgrade package with unmodified config file, changed in pkg
AT_SETUP([upgrade changing shared config])
AT_KEYWORDS([install])
AT_CHECK([
RPMDB_CLEAR
RPMDB_INIT
cf="${RPMTEST}"/etc/my.conf
rm -rf "${cf}" "${cf}".rpm*
rm -rf "${TOPDIR}"

for s in "A" "B"; do
    for v in "1.0" "2.0"; do
        runroot rpmbuild --quiet -bb \
            --define "sub $s" \
            --define "ver $v" \
	    --define "filedata foo-$v" \
              /data/SPECS/configtest.spec
    done
done

runroot rpm -U \
    "${TOPDIR}"/RPMS/noarch/configtest-A-1.0-1.noarch.rpm \
    "${TOPDIR}"/RPMS/noarch/configtest-B-1.0-1.noarch.rpm
cat "${cf}"
runroot rpm -U \
    "${TOPDIR}"/RPMS/noarch/configtest-A-2.0-1.noarch.rpm \
    "${TOPDIR}"/RPMS/noarch/configtest-B-2.0-1.noarch.rpm
cat "${cf}"
],
[0],
[foo-1.0
foo-2.0
],
[])
AT_CLEANUP

# ------------------------------
# Upgrade package with locally modified config file, changed in pkg
AT_SETUP([upgrade changing, modified shared config 1])
AT_KEYWORDS([install])
AT_CHECK([
RPMDB_CLEAR
RPMDB_INIT
cf="${RPMTEST}"/etc/my.conf
rm -rf "${cf}" "${cf}".rpm*
rm -rf "${TOPDIR}"

for s in "A" "B"; do
    for v in "1.0" "2.0"; do
        runroot rpmbuild --quiet -bb \
            --define "sub $s" \
            --define "ver $v" \
	    --define "filedata foo-$v" \
              /data/SPECS/configtest.spec
    done
done

runroot rpm -U \
    "${TOPDIR}"/RPMS/noarch/configtest-A-1.0-1.noarch.rpm \
    "${TOPDIR}"/RPMS/noarch/configtest-B-1.0-1.noarch.rpm
cat "${cf}"
echo "otherstuff" > "${RPMTEST}"/etc/my.conf
cat "${cf}"
runroot rpm -U \
    "${TOPDIR}"/RPMS/noarch/configtest-A-2.0-1.noarch.rpm \
    "${TOPDIR}"/RPMS/noarch/configtest-B-2.0-1.noarch.rpm
cat "${cf}"
cat "${cf}.rpmsave"
],
[0],
[foo-1.0
otherstuff
foo-2.0
otherstuff
],
[warning: /etc/my.conf saved as /etc/my.conf.rpmsave]
)
AT_CLEANUP

# ------------------------------
# Modified config file matches the content from new package.
AT_SETUP([upgrade changing, modified shared config 2])
AT_KEYWORDS([install])
AT_CHECK([
RPMDB_CLEAR
RPMDB_INIT
cf="${RPMTEST}"/etc/my.conf
rm -rf "${cf}" "${cf}".rpm*
rm -rf "${TOPDIR}"

for s in "A" "B"; do
    for v in "1.0" "2.0"; do
        runroot rpmbuild --quiet -bb \
            --define "sub $s" \
            --define "ver $v" \
	    --define "filedata foo-$v" \
              /data/SPECS/configtest.spec
    done
done

runroot rpm -U \
    "${TOPDIR}"/RPMS/noarch/configtest-A-1.0-1.noarch.rpm \
    "${TOPDIR}"/RPMS/noarch/configtest-B-1.0-1.noarch.rpm
cat "${cf}"
echo "foo-2.0" > "${RPMTEST}"/etc/my.conf
cat "${cf}"
runroot rpm -U \
    "${TOPDIR}"/RPMS/noarch/configtest-A-2.0-1.noarch.rpm \
    "${TOPDIR}"/RPMS/noarch/configtest-B-2.0-1.noarch.rpm
cat "${cf}"
],
[0],
[foo-1.0
foo-2.0
foo-2.0
],
[])
AT_CLEANUP

# Shared config(noreplace) variants of the more interesting cases
# ------------------------------
# Upgrade package with locally modified config file, changed in pkg.
AT_SETUP([upgrade changing, modified shared config(noreplace) 1])
AT_KEYWORDS([install])
AT_CHECK([
RPMDB_CLEAR
RPMDB_INIT
cf="${RPMTEST}"/etc/my.conf
rm -rf "${cf}" "${cf}".rpm*
rm -rf "${TOPDIR}"

for s in "A" "B"; do
    for v in "1.0" "2.0"; do
        runroot rpmbuild --quiet -bb \
            --define "sub $s" \
            --define "ver $v" \
	    --define "filedata foo-$v" \
	    --define "noreplace 1" \
              /data/SPECS/configtest.spec
    done
done

runroot rpm -U \
    "${TOPDIR}"/RPMS/noarch/configtest-A-1.0-1.noarch.rpm \
    "${TOPDIR}"/RPMS/noarch/configtest-B-1.0-1.noarch.rpm
cat "${cf}"
echo "otherstuff" > "${RPMTEST}"/etc/my.conf
cat "${cf}"
runroot rpm -U \
    "${TOPDIR}"/RPMS/noarch/configtest-A-2.0-1.noarch.rpm \
    "${TOPDIR}"/RPMS/noarch/configtest-B-2.0-1.noarch.rpm
cat "${cf}"
cat "${cf}.rpmnew"
],
[0],
[foo-1.0
otherstuff
otherstuff
foo-2.0
],
[warning: /etc/my.conf created as /etc/my.conf.rpmnew]
)
AT_CLEANUP

# ------------------------------
# Modified config file matches the content from new package.
AT_SETUP([upgrade changing, modified shared config(noreplace) 2])
AT_KEYWORDS([install])
AT_CHECK([
RPMDB_CLEAR
RPMDB_INIT
cf="${RPMTEST}"/etc/my.conf
rm -rf "${cf}" "${cf}".rpm*
rm -rf "${TOPDIR}"

for s in "A" "B"; do
    for v in "1.0" "2.0"; do
        runroot rpmbuild --quiet -bb \
            --define "sub $s" \
            --define "ver $v" \
	    --define "filedata foo-$v" \
	    --define "noreplace 1" \
              /data/SPECS/configtest.spec
    done
done

runroot rpm -U \
    "${TOPDIR}"/RPMS/noarch/configtest-A-1.0-1.noarch.rpm \
    "${TOPDIR}"/RPMS/noarch/configtest-B-1.0-1.noarch.rpm
cat "${cf}"
echo "foo-2.0" > "${RPMTEST}"/etc/my.conf
cat "${cf}"
runroot rpm -U \
    "${TOPDIR}"/RPMS/noarch/configtest-A-2.0-1.noarch.rpm \
    "${TOPDIR}"/RPMS/noarch/configtest-B-2.0-1.noarch.rpm
cat "${cf}"
],
[0],
[foo-1.0
foo-2.0
foo-2.0
],
[])
AT_CLEANUP

---------
# Test pre-existing and post-install config ghost survival and erasure
AT_SETUP([install/upgrade/erase ghost config])
AT_KEYWORDS([install])
AT_CHECK([
RPMDB_CLEAR
RPMDB_INIT
cf="${RPMTEST}"/etc/my.conf
rm -rf "${cf}" "${cf}".rpm*
rm -rf "${TOPDIR}"

for v in 1.0 2.0; do
    runroot rpmbuild --quiet -bb \
        --define "ver ${v}" \
        --define "filetype file" \
        --define "filedata buster" \
        --define "fileattr %ghost" \
          /data/SPECS/configtest.spec
done

# pre-existing config, install, erase
test ! -f "${cf}" && echo OK1
echo "keaton" > "${cf}"
cat "${cf}"
runroot rpm -U "${TOPDIR}"/RPMS/noarch/configtest-1.0-1.noarch.rpm
cat "${cf}"
runroot rpm -e configtest
cat "${cf}"
rm -f "${cf}"

# post-install config, upgrade, erase
runroot rpm -U "${TOPDIR}"/RPMS/noarch/configtest-1.0-1.noarch.rpm
test ! -f "${cf}" && echo OK2
echo "buster" > "${cf}"
cat "${cf}"
runroot rpm -U "${TOPDIR}"/RPMS/noarch/configtest-2.0-1.noarch.rpm
cat "${cf}"
runroot rpm -e configtest
cat "${cf}"
],
[],
[OK1
keaton
keaton
keaton
OK2
buster
buster
buster
],
[])
AT_CLEANUP
