]> wimlib.net Git - wimlib/commitdiff
Add update/extract tests
authorEric Biggers <ebiggers3@gmail.com>
Tue, 14 May 2013 00:58:47 +0000 (19:58 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Tue, 14 May 2013 00:58:47 +0000 (19:58 -0500)
Makefile.am
tests/test-imagex-update_and_extract [new file with mode: 0755]

index 18ac5b81fbb2f7ef05a1193f26f509513cbc2558..0aede5918141e3e181bfcfa733c6f80c9565cbb2 100644 (file)
@@ -179,7 +179,8 @@ check_PROGRAMS = tests/tree-cmp
 tests_tree_cmp_SOURCES = tests/tree-cmp.c
 
 dist_check_SCRIPTS = tests/test-imagex \
-                    tests/test-imagex-capture_and_apply
+                    tests/test-imagex-capture_and_apply \
+                    tests/test-imagex-update_and_extract
 
 if WITH_FUSE
 dist_check_SCRIPTS += tests/test-imagex-mount
diff --git a/tests/test-imagex-update_and_extract b/tests/test-imagex-update_and_extract
new file mode 100755 (executable)
index 0000000..7d5338f
--- /dev/null
@@ -0,0 +1,203 @@
+#!/usr/bin/env bash
+
+# Test `imagex update' and `imagex extract'.
+
+set -e
+cd tests
+srcdir="${srcdir:-.}/.."
+srcdir="$(cd $srcdir; pwd)"
+. "$srcdir/tests/tests-common.sh"
+
+TEST_SUBDIR=tmpdir_test-imagex-update_and_extract
+
+default_cleanup
+mkdir $TEST_SUBDIR
+cd $TEST_SUBDIR
+
+msg() {
+       echo "--------------------------------------------------------------------"
+       echo $1
+       echo "--------------------------------------------------------------------"
+}
+
+fail() {
+       msg "TEST FAILED (See above)"
+}
+
+trap fail exit
+
+prepare_empty_wim() {
+       rm -rf in.dir
+       mkdir in.dir
+       imagex capture in.dir test.wim
+}
+
+do_apply() {
+       rm -rf out.dir
+       imagex apply test.wim out.dir
+}
+
+prepare_empty_wim
+cp $srcdir/src/add_image.c file
+echo 1 > 1
+echo 2 > 2
+
+msg "Testing deleting nonexisting file from WIM image, without --force (errors expected)"
+! imagex update test.wim << EOF
+delete /nonexistent
+EOF
+
+msg "Testing deleting nonexisting file from WIM image, with --force"
+! imagex update test.wim << EOF
+delete --force /nonexistent
+EOF
+
+msg "Testing deleting root directory from WIM image, without --recursive (errors expected)"
+! imagex update test.wim << EOF
+delete /
+EOF
+
+msg "Testing deleting root directory from WIM image, with --recursive"
+imagex update test.wim << EOF
+delete --recursive /
+EOF
+
+msg "Testing update command with invalid option (errors expected)"
+! imagex update test.wim << EOF
+delete --invalid-option --recursive /
+EOF
+
+msg "Testing update command with too many arguments (errors expected)"
+! imagex update test.wim << EOF
+delete --recursive --force / /anotherdir
+EOF
+
+msg "Testing invalid update command (errors expected)"
+! imagex update test.wim << EOF
+invalid /
+EOF
+
+msg "Testing update command file with comments and empty lines"
+imagex update test.wim << EOF
+# this is a comment
+       # comment
+                       
+          
+# add
+# delete
+# rename
+
+EOF
+
+msg "Testing update with --rebuild"
+imagex update --rebuild test.wim < /dev/null
+
+for flag in "" "--rebuild"; do
+       msg "Testing adding file to WIM image with flag \"$flag\""
+       imagex update test.wim $flag << EOF
+add file /file
+EOF
+       do_apply
+       ../tree-cmp file out.dir/file
+
+       msg "Testing deleting file from WIM image"
+       imagex update test.wim << EOF
+delete /file
+EOF
+       do_apply
+       [ ! -e out.dir/file ]
+done
+
+msg "Testing renaming file in WIM image"
+imagex update test.wim << EOF
+add file /file
+EOF
+imagex update test.wim << EOF
+rename file newname
+EOF
+do_apply
+../tree-cmp file out.dir/newname && [ ! -e out.dir/file ]
+
+prepare_empty_wim
+msg "Testing adding, then renaming file in WIM image in one command"
+imagex update test.wim << EOF
+add file /file
+rename /file /newname
+EOF
+do_apply
+../tree-cmp file out.dir/newname && [ ! -e out.dir/file ]
+
+msg "Testing adding additional file to WIM image"
+prepare_empty_wim
+imagex update test.wim << EOF
+add 1 /1
+EOF
+imagex update test.wim << EOF
+add file /file
+EOF
+do_apply
+[ -e out.dir/1 ] && [ -e out.dir/file ]
+
+msg "Testing extracting file from WIM image"
+rm -rf out.dir && mkdir out.dir
+imagex extract test.wim 1 /file --dest-dir=out.dir
+../tree-cmp file out.dir/file && [ ! -e out.dir/1 ]
+
+msg "Testing extracting file from WIM image to stdout"
+rm -rf out.dir && mkdir out.dir
+../../imagex extract test.wim 1 /file --to-stdout > out.dir/file
+../tree-cmp file out.dir/file && [ ! -e out.dir/1 ]
+
+msg "Testing adding directories and files to WIM image"
+rm -rf dir1 && mkdir dir1
+rm -rf dir2 && mkdir dir2
+echo 5 > dir1/5
+echo 6 > dir2/6.1
+echo 6 > dir2/6
+echo 6 > dir2/6.2
+ln -s 5 dir1/relink
+mkdir dir1/subdir
+ln dir1/5 dir1/5link
+ln dir2/6 dir2/6link
+prepare_empty_wim
+imagex update test.wim 1 << EOF
+add dir1 /dir1
+add dir2 /prefix/dir2
+EOF
+rm -rf out.dir && mkdir out.dir
+imagex extract test.wim 1 dir1 --dest-dir=out.dir
+imagex extract test.wim 1 prefix/dir2 --dest-dir=out.dir
+../tree-cmp dir1 out.dir/dir1
+../tree-cmp dir2 out.dir/dir2
+
+msg "Testing adding files to WIM image"
+rm -rf in.dir && mkdir in.dir
+imagex append in.dir test.wim "2"
+cp $srcdir/src/*.c in.dir
+imagex update test.wim 2 << EOF
+add in.dir /
+add file /file
+EOF
+cp file in.dir/file
+rm -rf out.dir
+imagex apply test.wim 2 out.dir
+../tree-cmp in.dir out.dir
+
+msg "Testing adding file with space in it"
+echo hello > "Some File"
+prepare_empty_wim
+imagex update test.wim 1 << EOF
+       add     "Some File"     'Some Destination'
+EOF
+rm -rf out.dir
+imagex apply test.wim 1 out.dir
+../tree-cmp "Some File" out.dir/"Some Destination"
+
+
+echo "**********************************************************"
+echo "          imagex update/extract tests passed              "
+echo "**********************************************************"
+trap exit
+
+cd ..
+default_cleanup