diff options
-rw-r--r-- | README.testing | 20 | ||||
-rwxr-xr-x | tests/02_symlink_add_remove.sh | 19 | ||||
-rwxr-xr-x | tests/03_regular_file_add_remove.sh | 33 | ||||
-rwxr-xr-x | tests/run_tests.sh | 16 |
4 files changed, 77 insertions, 11 deletions
diff --git a/README.testing b/README.testing new file mode 100644 index 0000000..36f2453 --- /dev/null +++ b/README.testing @@ -0,0 +1,20 @@ +The testing framework basically aims to run the create and deploy tools in a +controlled environment to check for any regressions during code changes and +refactoring. + +This are the rules of the test club: + +- For each new feature there should be a unit test +- For each bug fixed there should be a unit test + +Running the test suite +---------------------- +You need to change to the tests directory and execute run_tests.sh: + +$ ./run_tests.sh + + +Anatomy of a unit test +---------------------- + +Each test diff --git a/tests/02_symlink_add_remove.sh b/tests/02_symlink_add_remove.sh index b3280c2..e4b81a9 100755 --- a/tests/02_symlink_add_remove.sh +++ b/tests/02_symlink_add_remove.sh @@ -1,7 +1,7 @@ #!/bin/bash -TEST_ID="01" -TEST_NAME="Simple symlink diff" +TEST_ID="03" +TEST_NAME="Symlink add/remove" CREATE=`pwd`/$1 DEPLOY=`pwd`/$2 @@ -14,18 +14,19 @@ TEST_TOOLS=$3 # This test checks that normal files content and metadata are function setup { - ln -s /foo $ORIGIN/a && \ - ln -s /bar $TARGET/a && \ - chown -h :cdrom $TARGET/a + ln -s /foo $ORIGIN/remove && \ + ln -s /bar $TARGET/add && \ + chown -h :cdrom $TARGET/add } # check_same_mtime FILE_A FILE_B function check_results { - test -L $ORIGIN/a && \ - check_symlink $ORIGIN/a "/bar" && \ - check_group $ORIGIN/a cdrom && \ - check_same_mtime $ORIGIN/a $ORIGIN/a + test -L $ORIGIN/add && \ + test ! -L $ORIGIN/remove && \ + check_symlink $ORIGIN/add "/bar" && \ + check_same_mtime $ORIGIN/add $TARGET/add && \ + check_same_uidgid $ORIGIN/add $TARGET/add } ############################################# diff --git a/tests/03_regular_file_add_remove.sh b/tests/03_regular_file_add_remove.sh new file mode 100755 index 0000000..f8b5652 --- /dev/null +++ b/tests/03_regular_file_add_remove.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +TEST_ID="01" +TEST_NAME="Regular file add remove" + +CREATE=`pwd`/$1 +DEPLOY=`pwd`/$2 +TEST_TOOLS=$3 + +. ./test_lib.sh + +############# Test specific code ############ + +# This test checks that normal files content and metadata are + +function setup { + touch $ORIGIN/remove && \ + echo 1 > $TARGET/add && \ + chown -h :cdrom $TARGET/add +} + +# check_same_mtime FILE_A FILE_B + +function check_results { + test -f $ORIGIN/add && \ + test ! -f $ORIGIN/remove && \ + check_content $ORIGIN/add "1" && \ + check_same_mtime $ORIGIN/add $TARGET/add && \ + check_same_uidgid $ORIGIN/add $TARGET/add +} + +############################################# +main $@ diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 024351e..873d2eb 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -1,15 +1,27 @@ #!/bin/bash -if [ ! -f $TESTLIB ] +if [ ! -f run_tests.sh ] +then + echo "Test suite needs to be run from the tests directory" 1>&2 + exit 1 +fi + +if [ ! -f test_lib.sh ] then echo "Could not find test_lib.sh" 1>&2 + exit 1 fi +ALLTESTSDIR=`pwd` + for i in [0-9][0-9]* do - ./$i $1 $2 + cd $ALLTESTSDIR + ./$i ../tbdiff-create ../tbdiff-deploy if [ $? -ne 0 ] then + echo "Test program $i failed" 1>&2 + cd $ALLTESTSDIR exit 1 fi done |