summaryrefslogtreecommitdiff
path: root/test/integration/test-failing-maintainer-scripts
blob: 953506aa5fef65e35a22529a7c882194c033b3f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/sh
set -e

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

setupenvironment
configarchitecture 'native'
configdpkgnoopchroot

# create a bunch of failures
createfailure() {
	setupsimplenativepackage "failure-$1" 'native' '1.0' 'unstable' 'Depends: dependee'
	BUILDDIR="incoming/failure-$1-1.0"
	echo '#!/bin/sh
exit 29' > ${BUILDDIR}/debian/$1
	buildpackage "$BUILDDIR" 'unstable' 'main' 'native'
	rm -rf "$BUILDDIR"
}

buildsimplenativepackage 'dependee' 'native' '1.0' 'unstable'
createfailure 'preinst'
createfailure 'postinst'
createfailure 'prerm'
createfailure 'postrm'

setupaptarchive

# setup some pre- and post- invokes to check the output isn't garbled later
APTHOOK="${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apthook"
echo '#!/bin/sh
echo "$1: START"
echo "$1: MaiN"
echo "$1: ENd"' > $APTHOOK
chmod +x $APTHOOK
echo "DPKG::Pre-Invoke:: \"${APTHOOK} PRE\";
DPKG::Post-Invoke:: \"${APTHOOK} POST\";" > rootdir/etc/apt/apt.conf.d/99apthooks

testmyfailure() {
	local PROGRESS='rootdir/tmp/progress.log'
	exec 3> $PROGRESS
	testfailure "$@" -o APT::Status-Fd=3
	msgtest 'Test for failure message of maintainerscript in' 'console log'
	local TEST='rootdir/tmp/testfailure.output'
	if grep -q 'exit status 29' "$TEST"; then
		msgpass
	else
		cat $TEST
		msgfail
	fi
	msgtest 'Test for proper execution of invoke scripts in' 'console log'
	if grep -q '^PRE: START$' $TEST &&
		grep -q '^PRE: MaiN$' $TEST &&
		grep -q '^PRE: ENd$' $TEST &&
		grep -q '^POST: START$' $TEST &&
		grep -q '^POST: MaiN$' $TEST &&
		grep -q '^POST: ENd$' $TEST; then
		msgpass
	else
		cat $TEST
		msgfail
	fi
	msgtest 'Test for failure message of maintainerscript in' 'progress log'
	if grep -q '^pmerror:.\+exit status 29$' "$PROGRESS"; then
		msgpass
	else
		cat $PROGRESS
		msgfail
	fi
	testmarkedauto 'dependee'
}

cp -a rootdir/var/lib/dpkg/status rootdir/var/lib/dpkg/status.backup
testmyfailure aptget install failure-preinst -y
cp -a rootdir/var/lib/dpkg/status.backup rootdir/var/lib/dpkg/status
testmyfailure aptget install failure-postinst -y
cp -a rootdir/var/lib/dpkg/status.backup rootdir/var/lib/dpkg/status
testsuccess aptget install failure-prerm -y
testdpkginstalled failure-prerm
testmyfailure aptget purge failure-prerm -y
cp -a rootdir/var/lib/dpkg/status.backup rootdir/var/lib/dpkg/status
testsuccess aptget install failure-postrm -y
testdpkginstalled failure-postrm
testmyfailure aptget purge failure-postrm -y

# FIXME: test with output going to a PTY as it usually does
#cp -a rootdir/var/lib/dpkg/status.backup rootdir/var/lib/dpkg/status
#aptget install failure-preinst -y