blob: 48966d0116ed6b119aabd0d09ebd88d4470287c4 (
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
#!/bin/sh
set -e
TESTDIR="$(readlink -f "$(dirname "$0")")"
. "$TESTDIR/framework"
setupenvironment
configarchitecture 'amd64'
buildsimplenativepackage 'pkg1' 'amd64' '1' 'stable'
buildsimplenativepackage 'pkg2' 'amd64' '1' 'stable'
setupaptarchive
cathistory() {
sed rootdir/var/log/apt/history.log -re 's/^(Commandline|Start-Date|End-Date):.*/\1: dummy/'
}
testsuccess aptget install pkg1
testequal "
Start-Date: dummy
Commandline: dummy
Install: pkg1:amd64 (1)
End-Date: dummy" cathistory
testsuccess aptget install pkg2 --comment="A test comment"
testequal "
Start-Date: dummy
Commandline: dummy
Install: pkg1:amd64 (1)
End-Date: dummy
Start-Date: dummy
Commandline: dummy
Comment: A test comment
Install: pkg2:amd64 (1)
End-Date: dummy" cathistory
normalizedinfo() {
apt history-info 0 | sed -E \
-e 's/^( *-?Start time *: ).*/\1dummy/' \
-e 's/^( *-?End time *: ).*/\1dummy/' \
-e 's|^( *-?Command line *: ).*/(.*)|\1\2|'
}
testsuccessequal "Transaction ID: 0
Start time: dummy
End time: dummy
Requested by:
Command line: apt-get install pkg1
Packages changed:
Install pkg1:amd64 (1)
" normalizedinfo
################################################################################
# Read previous history for manipulation
################################################################################
# Test history
# 0 - Install pkg1
# 1 - Install pkg2
# 2 - Remove pkg1 (undo ID 0)
# 3 - Install pkg1 (undo ID 2)
# 4 - Remove pkg1 (redo ID 2)
# 5 - Install pkg1 (rollback to ID 1)
# 6 - Remove pkg1 (rollback to ID 2)
testdpkginstalled pkg1
# undo the first package install
apt history-undo 0 -y >> /dev/null
testdpkgnotinstalled pkg1
# ...which generates a new id that we also undo
apt history-undo 2 -y >>/dev/null
testdpkginstalled pkg1
# redo the removal
apt history-redo 2 -y >> /dev/null
testdpkgnotinstalled pkg1
# rollback to ID 1 and it should be installed
apt history-rollback 1 -y >> /dev/null
testdpkginstalled pkg1
# rollback to ID 2 and it should be removed
apt history-rollback 2 -y >> /dev/null
testdpkgnotinstalled pkg1
# rollback to ID 0 and it should be installed
apt history-rollback 0 -y >> /dev/null
testdpkginstalled pkg1
# rollback to ID 4 and it should be removed
apt history-rollback 4 -y >> /dev/null
testdpkgnotinstalled pkg1
################################################################################
# Reset history log
################################################################################
msgmsg "Actionless group"
cat > rootdir/var/log/apt/history.log << EOF
Start-Date: dummy
Commandline: install nothing
End-Date: dummy
EOF
testsuccessequal "ID Command line Date and Time Action Changes
0 install nothing dummy 0 " apt history-list
testsuccessequal "Transaction ID: 0
Start time: dummy
End time: dummy
Requested by:
Command line: install nothing
Packages changed:" normalizedinfo
cat > rootdir/var/log/apt/history.log << EOF
Start-Date: 1970-01-01 00:00:00
Commandline: install nothing
Install: nothing
End-Date: 1970-01-01 00:00:00
Start-Date: 1971-01-01 00:00:00
Commandline: remove something
Remove: something
End-Date: 1971-01-01 00:00:00
EOF
testsuccessequal "ID Command line Date and Time Action Changes
0 install nothing 1970-01-01 00:00:00 Install 1
1 remove something 1971-01-01 00:00:00 Remove 1 " apt history-list
################################################################################
# Test different column widths
################################################################################
settestcolumnwidth() {
local columns=$1
local A_chars
A_chars=$(printf 'a%.0s' $(seq 1 "$columns"))
cat > rootdir/var/log/apt/history.log << EOF
Start-Date: dummy
Commandline: $A_chars
Install: nothing
End-Date: dummy
EOF
export COLUMNS="$columns"
}
settestcolumnwidth 80
testsuccessequal "ID Command line Date and Time Action Changes
0 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...dummy Install 1 " apt history-list
settestcolumnwidth 50
testsuccessequal "ID Command line Date and Time Action Changes
0 aaaaaaaaaaaaa...dummy Install 1 " apt history-list
settestcolumnwidth 100
testsuccessequal "ID Command line Date and Time Action Changes
0 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...dummy Install 1 " apt history-list
settestcolumnwidth 60
testsuccessequal "ID Command line Date and Time Action Changes
0 aaaaaaaaaaaaaaaaaaaaaaa...dummy Install 1 " apt history-list
testfailureequal "E: Incorrect usage, no ID was given." apt history-redo
testfailureequal "E: Incorrect usage, no ID was given." apt history-undo
testfailureequal "E: Incorrect usage, no ID was given." apt history-rollback
|