tdb: Add test for tdbdump command
authorChristof Schmitt <cs@samba.org>
Fri, 12 Apr 2024 22:44:38 +0000 (15:44 -0700)
committerChristof Schmitt <cs@samba.org>
Tue, 16 Apr 2024 17:32:34 +0000 (17:32 +0000)
Signed-off-by: Christof Schmitt <cs@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
lib/tdb/test/sample_tdb.txt [new file with mode: 0644]
lib/tdb/test/test_tdbdump.sh [new file with mode: 0755]
lib/tdb/wscript

diff --git a/lib/tdb/test/sample_tdb.txt b/lib/tdb/test/sample_tdb.txt
new file mode 100644 (file)
index 0000000..b9e0283
--- /dev/null
@@ -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 (executable)
index 0000000..08802f5
--- /dev/null
@@ -0,0 +1,53 @@
+#!/bin/sh
+# Test dumping of tdb database
+# Copyright (C) 2024 Christof Schmitt <cs@samba.org>
+
+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
index 2c587fbee44ac2f4bfb64cfca7040d99b9ea0a3b..e99800e902582c7e4fa2e81f3679b5d48e1fbf45 100644 (file)
@@ -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)