summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlberto <alberto.ruiz@codethink.co.uk>2011-09-30 19:20:22 +0100
committerAlberto <alberto.ruiz@codethink.co.uk>2011-09-30 19:20:22 +0100
commit69380730adccb560f4232c62ef3bade0be102185 (patch)
tree876dfe2bef04058bd81dcde8e9c97ced6da76a32 /tests
parent06dedc4631b4d8fcd589e71ba261baccc5fa1620 (diff)
downloadtbdiff-69380730adccb560f4232c62ef3bade0be102185.tar.gz
Added prototype of test suite
Diffstat (limited to 'tests')
-rwxr-xr-xtests/00_simple_file.sh30
-rwxr-xr-xtests/run_tests.sh15
-rw-r--r--tests/test_lib.sh82
3 files changed, 127 insertions, 0 deletions
diff --git a/tests/00_simple_file.sh b/tests/00_simple_file.sh
new file mode 100755
index 0000000..85ecbcd
--- /dev/null
+++ b/tests/00_simple_file.sh
@@ -0,0 +1,30 @@
+#!/bin/bash
+
+TEST_ID="00"
+TEST_NAME="Simple file diff"
+
+CREATE=`pwd`/$1
+DEPLOY=`pwd`/$2
+TEST_TOOLS=$3
+
+. ./test_lib.sh
+
+function setup {
+ rm -rf $TESTDIR
+ mkdir -p $ORIGIN && \
+ mkdir -p $TARGET && \
+ echo 1 > $ORG_FILE && \
+ echo 2 > $TGT_FILE && \
+ chgrp cdrom $TGT_FILE && \
+ chmod 707 $TGT_FILE
+}
+
+# check_same_mtime FILE_A FILE_B
+
+function check_results {
+ check_content $ORG_FILE "2" && \
+ check_perm $ORG_FILE 707 && \
+ check_same_mtime $ORG_FILE $TGT_FILE
+}
+
+main
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
new file mode 100755
index 0000000..024351e
--- /dev/null
+++ b/tests/run_tests.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+if [ ! -f $TESTLIB ]
+then
+ echo "Could not find test_lib.sh" 1>&2
+fi
+
+for i in [0-9][0-9]*
+do
+ ./$i $1 $2
+ if [ $? -ne 0 ]
+ then
+ exit 1
+ fi
+done
diff --git a/tests/test_lib.sh b/tests/test_lib.sh
new file mode 100644
index 0000000..1e0a838
--- /dev/null
+++ b/tests/test_lib.sh
@@ -0,0 +1,82 @@
+OK=" OK"
+FAIL=" FAIL"
+
+TESTDIR=/tmp/tbdiff-test-`uuid`
+IMGFILE=$TESTDIR/tbdiff.img
+ORIGIN=$TESTDIR/orig
+TARGET=$TESTDIR/target
+
+ORG_FILE=$ORIGIN/b.txt
+TGT_FILE=$TARGET/b.txt
+
+function check_same_mtime {
+ test $(stat -c %Y $1) = $(stat -c %Y $2)
+}
+
+# check_content FILE EXPECTED_OCTAL_PERMISSIONS
+function check_perm {
+ test $(stat -c %a $1) = $2
+}
+
+# check_content FILE EXPECTED_CONTENT
+function check_content {
+ test $(cat $1) = $2
+}
+
+function start {
+ if [ ! -f $1 ]
+ then
+ echo "ERROR: $1 is an invalid tbdiff-create path" 1>&2
+ cleanup_and_exit
+ fi
+
+ if [ ! -f $2 ]
+ then
+ echo "ERROR: $1 is an invalid tbdiff-deploy path" 1>&2
+ cleanup_and_exit
+ fi
+}
+
+function cleanup_and_exit {
+ rm -rf $TESTDIR
+ exit 1
+}
+
+function main {
+ start
+ echo -n "$TEST_ID Setting up $TEST_NAME test: "
+ setup
+ if [ $? -ne 0 ]
+ then
+ echo $FAIL
+ echo "Couldn't setup the test directory structure. Check your privileges" 1>&2
+ cleanup_and_exit
+ fi
+ echo $OK
+
+ echo -n "$TEST_ID Performing $TEST_NAME image creation and deployment: "
+ CWD=$(pwd)
+ $CREATE $IMGFILE $ORIGIN $TARGET && \
+ cd $ORIGIN && \
+ $DEPLOY $IMGFILE && \
+ RET=$?
+ cd $CWD
+
+ if [ $RET -ne 0 ]
+ then
+ echo $FAIL
+ echo "Could not create and deploy image." 1>&2
+ cleanup_and_exit
+ fi
+ echo $OK
+
+ echo -n "$TEST_ID Checking $TEST_NAME results: "
+ check_results
+ if [ $RET -ne 0 ]
+ then
+ echo $FAIL
+ echo "Applying image did not produce the expected results" 1>&2
+ cleanup_and_exit
+ fi
+ echo $OK
+}