]> wimlib.net Git - wimlib/blob - tests/test-imagex-update_and_extract
imagex-mount.1.in: Fix typo
[wimlib] / tests / test-imagex-update_and_extract
1 #!/usr/bin/env bash
2
3 # Test `imagex update' and `imagex extract'.
4
5 set -e
6 cd tests
7 srcdir="${srcdir:-.}/.."
8 srcdir="$(cd $srcdir; pwd)"
9 . "$srcdir/tests/tests-common.sh"
10
11 TEST_SUBDIR=tmpdir_test-imagex-update_and_extract
12
13 default_cleanup
14 mkdir $TEST_SUBDIR
15 cd $TEST_SUBDIR
16
17 msg() {
18         echo "--------------------------------------------------------------------"
19         echo $1
20         echo "--------------------------------------------------------------------"
21 }
22
23 fail() {
24         msg "TEST FAILED (See above)"
25 }
26
27 trap fail exit
28
29 prepare_empty_wim() {
30         rm -rf in.dir
31         mkdir in.dir
32         imagex capture in.dir test.wim
33 }
34
35 do_apply() {
36         rm -rf out.dir
37         imagex apply test.wim out.dir
38 }
39
40 prepare_empty_wim
41 cp $srcdir/src/add_image.c file
42 echo 1 > 1
43 echo 2 > 2
44
45 msg "Testing deleting nonexisting file from WIM image, without --force (errors expected)"
46 ! imagex update test.wim << EOF
47 delete /nonexistent
48 EOF
49
50 msg "Testing deleting nonexisting file from WIM image, with --force"
51 ! imagex update test.wim << EOF
52 delete --force /nonexistent
53 EOF
54
55 msg "Testing deleting root directory from WIM image, without --recursive (errors expected)"
56 ! imagex update test.wim << EOF
57 delete /
58 EOF
59
60 msg "Testing deleting root directory from WIM image, with --recursive"
61 imagex update test.wim << EOF
62 delete --recursive /
63 EOF
64
65 msg "Testing update command with invalid option (errors expected)"
66 ! imagex update test.wim << EOF
67 delete --invalid-option --recursive /
68 EOF
69
70 msg "Testing update command with too many arguments (errors expected)"
71 ! imagex update test.wim << EOF
72 delete --recursive --force / /anotherdir
73 EOF
74
75 msg "Testing invalid update command (errors expected)"
76 ! imagex update test.wim << EOF
77 invalid /
78 EOF
79
80 msg "Testing update command file with comments and empty lines"
81 imagex update test.wim << EOF
82 # this is a comment
83         # comment
84                         
85            
86 # add
87 # delete
88 # rename
89
90 EOF
91
92 msg "Testing update with --rebuild"
93 imagex update --rebuild test.wim < /dev/null
94
95 for flag in "" "--rebuild"; do
96         msg "Testing adding file to WIM image with flag \"$flag\""
97         imagex update test.wim $flag << EOF
98 add file /file
99 EOF
100         do_apply
101         ../tree-cmp file out.dir/file
102
103         msg "Testing deleting file from WIM image"
104         imagex update test.wim << EOF
105 delete /file
106 EOF
107         do_apply
108         [ ! -e out.dir/file ]
109 done
110
111 msg "Testing renaming file in WIM image"
112 imagex update test.wim << EOF
113 add file /file
114 EOF
115 imagex update test.wim << EOF
116 rename file newname
117 EOF
118 do_apply
119 ../tree-cmp file out.dir/newname && [ ! -e out.dir/file ]
120
121 prepare_empty_wim
122 msg "Testing adding, then renaming file in WIM image in one command"
123 imagex update test.wim << EOF
124 add file /file
125 rename /file /newname
126 EOF
127 do_apply
128 ../tree-cmp file out.dir/newname && [ ! -e out.dir/file ]
129
130 msg "Testing adding additional file to WIM image"
131 prepare_empty_wim
132 imagex update test.wim << EOF
133 add 1 /1
134 EOF
135 imagex update test.wim << EOF
136 add file /file
137 EOF
138 do_apply
139 [ -e out.dir/1 ] && [ -e out.dir/file ]
140
141 msg "Testing extracting file from WIM image"
142 rm -rf out.dir && mkdir out.dir
143 imagex extract test.wim 1 /file --dest-dir=out.dir
144 ../tree-cmp file out.dir/file && [ ! -e out.dir/1 ]
145
146 msg "Testing extracting file from WIM image to stdout"
147 rm -rf out.dir && mkdir out.dir
148 ../../imagex extract test.wim 1 /file --to-stdout > out.dir/file
149 ../tree-cmp file out.dir/file && [ ! -e out.dir/1 ]
150
151 msg "Testing adding directories and files to WIM image"
152 rm -rf dir1 && mkdir dir1
153 rm -rf dir2 && mkdir dir2
154 echo 5 > dir1/5
155 echo 6 > dir2/6.1
156 echo 6 > dir2/6
157 echo 6 > dir2/6.2
158 ln -s 5 dir1/relink
159 mkdir dir1/subdir
160 ln dir1/5 dir1/5link
161 ln dir2/6 dir2/6link
162 prepare_empty_wim
163 imagex update test.wim 1 << EOF
164 add dir1 /dir1
165 add dir2 /prefix/dir2
166 EOF
167 rm -rf out.dir && mkdir out.dir
168 imagex extract test.wim 1 dir1 --dest-dir=out.dir
169 imagex extract test.wim 1 prefix/dir2 --dest-dir=out.dir
170 ../tree-cmp dir1 out.dir/dir1
171 ../tree-cmp dir2 out.dir/dir2
172
173 msg "Testing adding files to WIM image"
174 rm -rf in.dir && mkdir in.dir
175 imagex append in.dir test.wim "2"
176 cp $srcdir/src/*.c in.dir
177 imagex update test.wim 2 << EOF
178 add in.dir /
179 add file /file
180 EOF
181 cp file in.dir/file
182 rm -rf out.dir
183 imagex apply test.wim 2 out.dir
184 ../tree-cmp in.dir out.dir
185
186 msg "Testing adding file with space in it"
187 echo hello > "Some File"
188 prepare_empty_wim
189 imagex update test.wim 1 << EOF
190         add     "Some File"     'Some Destination'
191 EOF
192 rm -rf out.dir
193 imagex apply test.wim 1 out.dir
194 ../tree-cmp "Some File" out.dir/"Some Destination"
195
196
197 echo "**********************************************************"
198 echo "          imagex update/extract tests passed              "
199 echo "**********************************************************"
200 trap exit
201
202 cd ..
203 default_cleanup