From: Christof Schmitt Date: Fri, 12 Apr 2024 22:44:38 +0000 (-0700) Subject: tdb: Add test for tdbdump command X-Git-Tag: tdb-1.4.11~1104 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f6a47de2dbdb04096cf4bf147d149317cec3a235;p=thirdparty%2Fsamba.git tdb: Add test for tdbdump command Signed-off-by: Christof Schmitt Reviewed-by: Andrew Bartlett --- diff --git a/lib/tdb/test/sample_tdb.txt b/lib/tdb/test/sample_tdb.txt new file mode 100644 index 00000000000..b9e028353e2 --- /dev/null +++ b/lib/tdb/test/sample_tdb.txt @@ -0,0 +1,12 @@ +{ +key(11) = "nbt_server\00" +data(35) = "972.2147483648/1085706313786795392\00" +} +{ +key(15) = "winbind_server\00" +data(25) = "977/12826542715097898407\00" +} +{ +key(14) = "notify-daemon\00" +data(24) = "992/6389638235474936598\00" +} diff --git a/lib/tdb/test/test_tdbdump.sh b/lib/tdb/test/test_tdbdump.sh new file mode 100755 index 00000000000..08802f516a6 --- /dev/null +++ b/lib/tdb/test/test_tdbdump.sh @@ -0,0 +1,53 @@ +#!/bin/sh +# Test dumping of tdb database +# Copyright (C) 2024 Christof Schmitt + +if [ $# -lt 3 ]; then + echo "Usage: $0 TDB_FILE EXPECTED_DUMP EXPECTED_DUMP_X" + exit 1 +fi + +TDB_FILE=$1 +EXPECTED_DUMP=$2 +TEMP_DUMP=tempdump.txt + +failed=0 + +timestamp() +{ + date -u +'time: %Y-%m-%d %H:%M:%S.%6NZ' | sed 's/\..*NZ$/.000000Z/' +} + +subunit_fail_test() +{ + timestamp + printf 'failure: %s [\n' "$1" + cat - + echo "]" +} + +testit() +{ + name="$1" + shift + cmdline="$@" + timestamp + printf 'test: %s\n' "$1" + output=$($cmdline 2>&1) + status=$? + if [ x$status = x0 ]; then + timestamp + printf 'success: %s\n' "$name" + else + echo "$output" | subunit_fail_test "$name" + fi + return $status +} + +$BINDIR/tdbdump $TDB_FILE > $TEMP_DUMP +testit "Verifying tdbdump" cmp $TEMP_DUMP $EXPECTED_DUMP \ + || failed=$(expr $failed + 1) + +rm $TEMP_DUMP + +exit $failed diff --git a/lib/tdb/wscript b/lib/tdb/wscript index 2c587fbee44..e99800e9025 100644 --- a/lib/tdb/wscript +++ b/lib/tdb/wscript @@ -216,7 +216,8 @@ def testonly(ctx): if not os.path.exists(link): os.symlink(ctx.path.make_node('test').abspath(), link) - sh_tests = ["test/test_tdbbackup.sh test/jenkins-be-hash.tdb"] + sh_tests = ["test/test_tdbbackup.sh test/jenkins-be-hash.tdb", + "test/test_tdbdump.sh test/sample_tdb.tdb test/sample_tdb.txt"] for sh_test in sh_tests: cmd = "BINDIR=%s %s" % (blddir, sh_test)