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