From 69380730adccb560f4232c62ef3bade0be102185 Mon Sep 17 00:00:00 2001 From: Alberto Date: Fri, 30 Sep 2011 19:20:22 +0100 Subject: Added prototype of test suite --- tests/00_simple_file.sh | 30 ++++++++++++++++++ tests/run_tests.sh | 15 +++++++++ tests/test_lib.sh | 82 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+) create mode 100755 tests/00_simple_file.sh create mode 100755 tests/run_tests.sh create mode 100644 tests/test_lib.sh (limited to 'tests') 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 +} -- cgit v1.2.1