Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/tests/frontend/configmerge.sh
2065 views
1
#!/usr/bin/env atf-sh
2
3
. $(atf_get_srcdir)/test_environment.sh
4
tests_init \
5
config \
6
config_conflict \
7
config_duplicate \
8
config_duplicate_keyword \
9
config_fileexist \
10
config_filenotexist \
11
config_fileexist_notinpkg \
12
config_hardlink \
13
config_morecomplicated
14
15
config_body()
16
{
17
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1"
18
echo "@config ${TMPDIR}/a" > plist
19
20
echo "entry" > a
21
22
atf_check \
23
pkg create -M test.ucl -p plist
24
25
atf_check \
26
-o match:"^config" \
27
pkg info -R --raw-format ucl -F ${TMPDIR}/test-1.pkg
28
29
mkdir ${TMPDIR}/target
30
unset PKG_DBDIR
31
atf_check \
32
pkg -o REPOS_DIR=/dev/null -r ${TMPDIR}/target install -qy ${TMPDIR}/test-1.pkg
33
test -f ${TMPDIR}/target/${TMPDIR}/a || atf_fail "file absent"
34
echo "addition" >> ${TMPDIR}/target/${TMPDIR}/a
35
atf_check \
36
-o inline:"entry\naddition\n" \
37
cat ${TMPDIR}/target/${TMPDIR}/a
38
39
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "2"
40
echo "entry 2" > a
41
42
atf_check \
43
pkg create -M test.ucl -p plist
44
45
pkg repo .
46
mkdir reposconf
47
echo "local: { url: file://${TMPDIR} }" > reposconf/local.conf
48
atf_check \
49
pkg -o REPOS_DIR=${TMPDIR}/reposconf -r ${TMPDIR}/target upgrade -qy test
50
51
atf_check \
52
-o inline:"entry 2\naddition\n" \
53
cat ${TMPDIR}/target/${TMPDIR}/a
54
}
55
56
# Make sure that config file modifications are preserved across split upgrades.
57
# Here, package "test" contains a config file, and the "other" package introduces a
58
# conflict on upgrade when file "b" moves from "test" to "other". To resolve the
59
# conflict, pkg must temporarily uninstall "test", and we check that modifications
60
# to the config file are not lost.
61
config_conflict_body()
62
{
63
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1"
64
echo "@config ${TMPDIR}/a" > plist
65
echo "${TMPDIR}/b" >> plist
66
67
echo "be provocative" > a
68
touch b
69
70
atf_check \
71
pkg create -M test.ucl -p plist
72
73
atf_check \
74
-o match:"^config" \
75
pkg info -R --raw-format ucl -F ${TMPDIR}/test-1.pkg
76
77
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "2"
78
echo "@config ${TMPDIR}/a" > plist
79
80
atf_check \
81
pkg create -M test.ucl -p plist
82
83
atf_check \
84
-o match:"^config" \
85
pkg info -R --raw-format ucl -F ${TMPDIR}/test-2.pkg
86
87
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "other" "other" "1"
88
echo "${TMPDIR}/c" > plist
89
90
touch c
91
92
atf_check \
93
pkg create -M other.ucl -p plist
94
95
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "other" "other" "2"
96
echo "${TMPDIR}/b" > plist
97
echo "${TMPDIR}/c" >> plist
98
99
touch c
100
101
atf_check \
102
pkg create -M other.ucl -p plist
103
104
mkdir ${TMPDIR}/target
105
unset PKG_DBDIR
106
atf_check \
107
pkg -o REPOS_DIR=/dev/null -r ${TMPDIR}/target install -qy ${TMPDIR}/test-1.pkg
108
atf_check \
109
pkg -o REPOS_DIR=/dev/null -r ${TMPDIR}/target install -qy ${TMPDIR}/other-1.pkg
110
test -f ${TMPDIR}/target/${TMPDIR}/a || atf_fail "file absent"
111
112
echo "be organized" >> ${TMPDIR}/target/${TMPDIR}/a
113
114
pkg repo .
115
mkdir reposconf
116
echo "local: { url: file://${TMPDIR} }" > reposconf/local.conf
117
atf_check \
118
pkg -o REPOS_DIR=${TMPDIR}/reposconf -r ${TMPDIR}/target upgrade -qy
119
120
test -f ${TMPDIR}/target/${TMPDIR}/a || atf_fail "file absent"
121
122
atf_check \
123
-o inline:"be provocative\nbe organized\n" \
124
cat ${TMPDIR}/target/${TMPDIR}/a
125
}
126
127
config_duplicate_body()
128
{
129
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1"
130
cat >> test.ucl << EOF
131
files: {
132
"${TMPDIR}/a": "$sum"
133
}
134
135
config: [
136
"${TMPDIR}/a",
137
"${TMPDIR}/a"
138
]
139
EOF
140
141
echo "entry" > a
142
143
atf_check -s exit:1 -e match:"pkg: duplicate file listing: .*" \
144
pkg create -M test.ucl
145
}
146
147
config_duplicate_keyword_body()
148
{
149
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1"
150
echo "@config ${TMPDIR}/a" > plist
151
echo "@config ${TMPDIR}/a" >> plist
152
153
echo "entry" > a
154
155
atf_check -s exit:1 -e match:"pkg: duplicate file listing: .*" \
156
pkg create -M test.ucl -p plist
157
}
158
159
config_fileexist_body()
160
{
161
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1"
162
echo "${TMPDIR}/a" > plist
163
164
echo "entry" > a
165
166
atf_check \
167
pkg create -M test.ucl -p plist
168
169
mkdir ${TMPDIR}/target
170
unset PKG_DBDIR
171
atf_check \
172
pkg -o REPOS_DIR=/dev/null -r ${TMPDIR}/target install -qy ${TMPDIR}/test-1.pkg
173
test -f ${TMPDIR}/target/${TMPDIR}/a || atf_fail "file absent"
174
echo "addition" >> ${TMPDIR}/target/${TMPDIR}/a
175
atf_check \
176
-o inline:"entry\naddition\n" \
177
cat ${TMPDIR}/target/${TMPDIR}/a
178
179
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "2"
180
echo "entry 2" > a
181
echo "@config ${TMPDIR}/a" > plist
182
183
atf_check \
184
pkg create -M test.ucl -p plist
185
186
pkg repo .
187
mkdir reposconf
188
echo "local: { url: file://${TMPDIR} }" > reposconf/local.conf
189
atf_check \
190
pkg -o REPOS_DIR=${TMPDIR}/reposconf -r ${TMPDIR}/target upgrade -qy test
191
192
test -f ${TMPDIR}/target/${TMPDIR}/a.pkgnew || atf_fail "file overwritten when it should not have"
193
}
194
195
config_filenotexist_body()
196
{
197
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1"
198
echo "${TMPDIR}/a" > plist
199
200
echo "entry" > a
201
202
atf_check \
203
pkg create -M test.ucl -p plist
204
205
mkdir ${TMPDIR}/target
206
unset PKG_DBDIR
207
atf_check \
208
pkg -o REPOS_DIR=/dev/null -r ${TMPDIR}/target install -qy ${TMPDIR}/test-1.pkg
209
test -f ${TMPDIR}/target/${TMPDIR}/a || atf_fail "file absent"
210
echo "addition" >> ${TMPDIR}/target/${TMPDIR}/a
211
atf_check \
212
-o inline:"entry\naddition\n" \
213
cat ${TMPDIR}/target/${TMPDIR}/a
214
215
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "2"
216
echo "entry 2" > a
217
echo "@config ${TMPDIR}/a" > plist
218
219
atf_check \
220
pkg create -M test.ucl -p plist
221
222
pkg repo .
223
mkdir reposconf
224
echo "local: { url: file://${TMPDIR} }" > reposconf/local.conf
225
rm ${TMPDIR}/target/${TMPDIR}/a
226
atf_check \
227
pkg -o REPOS_DIR=${TMPDIR}/reposconf -r ${TMPDIR}/target upgrade -qy test
228
229
test ! -f ${TMPDIR}/target/${TMPDIR}/a.pkgnew || atf_fail "redundant pkgnew left hanging"
230
test -f ${TMPDIR}/target/${TMPDIR}/a || atf_fail "config file not installed"
231
}
232
233
config_hardlink_body()
234
{
235
# Create a pkg
236
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1.0"
237
echo "line 1" > a
238
echo "line 2" >> a
239
ln a b
240
echo "@config /a" > plist
241
echo "/b" >> plist
242
atf_check \
243
-o empty \
244
-e empty \
245
pkg create -M test.ucl -p plist -r .
246
atf_check -o ignore pkg repo .
247
mkdir reposconf
248
echo "local: { url: file://${TMPDIR} }" > reposconf/local.conf
249
mkdir ${TMPDIR}/target
250
251
# Install the pkg
252
atf_check \
253
pkg -o REPOS_DIR=${TMPDIR}/reposconf -r ${TMPDIR}/target install -qy test
254
rm *.pkg
255
256
# Modify the local config
257
echo "line 1a" > target/a
258
echo "line 2" >> target/a
259
260
# Create an updated pkg
261
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1.1"
262
echo "line 1" > a
263
echo "line 2" >> a
264
echo "@config /a" > plist
265
echo "/b" >> plist
266
atf_check \
267
-o empty \
268
-e empty \
269
pkg create -M test.ucl -p plist -r .
270
atf_check -o ignore pkg repo .
271
atf_check -e ignore -o ignore pkg -o REPOS_DIR=${TMPDIR}/reposconf update -f
272
273
# Upgrade
274
atf_check \
275
-o ignore \
276
pkg -o REPOS_DIR=${TMPDIR}/reposconf -r ${TMPDIR}/target upgrade -y
277
278
atf_check \
279
-o match:"test-1.1*" \
280
pkg -r ${TMPDIR}/target info
281
282
}
283
284
config_fileexist_notinpkg_body()
285
{
286
mkdir -p ${TMPDIR}/target/${TMPDIR}
287
echo "entry" > ${TMPDIR}/target/${TMPDIR}/a
288
unset PKG_DBDIR
289
290
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "2"
291
echo "entry 2" > a
292
echo "@config ${TMPDIR}/a" > plist
293
294
atf_check \
295
pkg create -M test.ucl -p plist
296
297
pkg repo .
298
mkdir reposconf
299
echo "local: { url: file://${TMPDIR} }" > reposconf/local.conf
300
atf_check \
301
pkg -o REPOS_DIR=${TMPDIR}/reposconf -r ${TMPDIR}/target install -qy test
302
303
test -f ${TMPDIR}/target/${TMPDIR}/a.pkgsave || atf_fail "file overwritten when it should not have"
304
}
305
306
config_morecomplicated_body()
307
{
308
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1"
309
echo "entry1" > test.config
310
echo "entry3" >> test.config
311
echo "@config ${TMPDIR}/test.config" > plist
312
313
atf_check \
314
pkg create -M test.ucl -p plist
315
316
atf_check \
317
-o match:"^config" \
318
pkg info -R --raw-format ucl -F ${TMPDIR}/test-1.pkg
319
320
mkdir ${TMPDIR}/target
321
unset PKG_DBDIR
322
atf_check \
323
pkg -o REPOS_DIR=/dev/null -r ${TMPDIR}/target install -qy ${TMPDIR}/test-1.pkg
324
test -f ${TMPDIR}/target/${TMPDIR}/test.config || atf_fail "file absent"
325
326
atf_check \
327
-o inline:"entry1\nentry3\n" \
328
cat ${TMPDIR}/target/${TMPDIR}/test.config
329
330
echo "entry4" >> ${TMPDIR}/target/${TMPDIR}/test.config
331
atf_check \
332
-o inline:"entry1\nentry3\nentry4\n" \
333
cat ${TMPDIR}/target/${TMPDIR}/test.config
334
335
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "2"
336
echo "entry1" > test.config
337
echo "entry2" >> test.config
338
echo "entry3" >> test.config
339
340
atf_check \
341
pkg create -M test.ucl -p plist
342
343
atf_check \
344
-o ignore \
345
pkg repo .
346
347
mkdir reposconf
348
echo "local: { url: file://${TMPDIR} }" > reposconf/local.conf
349
atf_check \
350
pkg -o REPOS_DIR=${TMPDIR}/reposconf -r ${TMPDIR}/target upgrade -qy test
351
352
atf_check \
353
-o inline:"entry1\nentry2\nentry3\nentry4\n" \
354
cat ${TMPDIR}/target/${TMPDIR}/test.config
355
}
356
357