]> the.earth.li Git - onak.git/commitdiff
Add basic testing infrastructure + initial tests
authorJonathan McDowell <noodles@earth.li>
Sun, 24 Apr 2011 02:28:31 +0000 (19:28 -0700)
committerJonathan McDowell <noodles@earth.li>
Sun, 24 Apr 2011 02:28:31 +0000 (19:28 -0700)
  Add some simple scripts to ensure key addition, deletion and retrieval
  are at least working ok.

Makefile.in
runtests [new file with mode: 0755]
t/all-020-get.t [new file with mode: 0755]
t/all-030-get-fail.t [new file with mode: 0755]
t/all-040-index-text.t [new file with mode: 0755]
t/db4-000-add.t [new file with mode: 0755]
t/file-000-add.t [new file with mode: 0755]
t/file-010-del.t [new file with mode: 0755]
t/fs-000-add.t [new file with mode: 0755]
t/fs-010-del.t [new file with mode: 0755]
t/test-in.conf [new file with mode: 0644]

index 4ec39dad8fbbc4b71da02ba3191010ee8f6b9638..f294acda337403ae78bb4515013026e430683ea9 100644 (file)
@@ -48,6 +48,9 @@ OBJS = stats.o cleankey.o $(CORE_OBJS) $(KEYDB_OBJ)
 all: .depend $(PROGS) testparse maxpath sixdegrees splitkeys onak.conf \
        $(BACKENDS)
 
+test: onak $(BACKENDS)
+       @./runtests
+
 install: $(PROGS) onak.conf $(BACKENDS)
        install -d $(DESTDIR)/@bindir@
        install -d $(DESTDIR)/@libdir@/onak/backends
diff --git a/runtests b/runtests
new file mode 100755 (executable)
index 0000000..968cfc0
--- /dev/null
+++ b/runtests
@@ -0,0 +1,41 @@
+#!/bin/sh
+set -e
+
+fail=0
+total=0
+
+if [ ! -e onak ]; then
+       echo "** onak binary doesn't exist, cannot run test suite" >&2
+       exit 1
+fi
+
+if [ -e t/db/ ]; then
+       rm -rf t/db/
+fi
+
+for t in libkeydb_*.so; do
+       backend=${t##libkeydb_}
+       backend=${backend%%.so}
+       if [ "`echo t/$backend-*`" != "t/$backend-*" ]; then
+               echo "* testing $backend backend"
+               (sed -e "s;DIR;`pwd`;" t/test-in.conf ; \
+                       echo db_backend $backend) > t/test.conf
+               for t in t/$backend-*.t t/all-*.t; do
+                       total=`expr $total + 1`
+                       mkdir t/db/
+                       if ! $t $backend; then
+                               echo "test $t failed" >&2
+                               fail=`expr $fail + 1`
+                       fi
+                       rm -rf t/db/
+               done
+               rm t/test.conf
+       fi
+done
+
+if [ "$fail" -gt 0 ]; then
+       echo "** failed $fail/$total tests" >&2
+       exit 1
+else
+       echo "** all tests succeeded"
+fi
diff --git a/t/all-020-get.t b/t/all-020-get.t
new file mode 100755 (executable)
index 0000000..8adaa3f
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/sh
+# Check we can retrieve a key by keyid
+
+set -e
+
+cd t
+../onak -b -c test.conf add < ../keys/noodles.key
+if ! ../onak -c test.conf get 0x2DA8B985 2> /dev/null | \
+       grep -q -- '-----BEGIN PGP PUBLIC KEY BLOCK-----'; then
+       echo "* Did not correctly retrieve key by keyid."
+       exit 1
+fi
+
+exit 0
diff --git a/t/all-030-get-fail.t b/t/all-030-get-fail.t
new file mode 100755 (executable)
index 0000000..0db2b28
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/sh
+# Check retrieving a non existent keyid fails
+
+set -e
+
+cd t
+../onak -b -c test.conf add < ../keys/noodles.key
+if ! ../onak -c test.conf get 0x12345678 2>&1 | \
+       grep -q 'Key not found'; then
+       echo "* Did not correctly error on non-existent key"
+       exit 1
+fi
+
+exit 0
diff --git a/t/all-040-index-text.t b/t/all-040-index-text.t
new file mode 100755 (executable)
index 0000000..f5b1c14
--- /dev/null
@@ -0,0 +1,20 @@
+#!/bin/sh
+# Check we can index a key by some uid text
+
+set -e
+
+# Backends should really support this, but the file one is as simple as
+# possible, so doesn't. Skip the test for it.
+if [ "$1" = "file" ]; then
+       exit 0
+fi
+
+cd t
+../onak -b -c test.conf add < ../keys/noodles.key
+if ! ../onak -c test.conf index noodles 2> /dev/null | \
+       grep -q -- 'pub   4096R/2DA8B985 2008/06/03 Jonathan McDowell'; then
+       echo "* Did not correctly retrieve key by text"
+       exit 1
+fi
+
+exit 0
diff --git a/t/db4-000-add.t b/t/db4-000-add.t
new file mode 100755 (executable)
index 0000000..c69cabb
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/sh
+# Check we can add a key successfully with the db4 backend.
+
+set -e
+
+cd t
+../onak -b -c test.conf add < ../keys/noodles.key
+if [ ! -e db/worddb -o ! -e db/id32db -o ! -e db/keydb.0.db ]; then
+       echo Did not correctly add key using db4 backend.
+       exit 1
+fi
+
+exit 0
diff --git a/t/file-000-add.t b/t/file-000-add.t
new file mode 100755 (executable)
index 0000000..cd7a4c5
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/sh
+# Check we can add a key successfully with the file backend.
+
+set -e
+
+cd t
+../onak -b -c test.conf add < ../keys/noodles.key
+if [ ! -e db/0x2DA8B985 ]; then
+       echo Did not correctly add key using file backend.
+       exit 1
+fi
+
+exit 0
diff --git a/t/file-010-del.t b/t/file-010-del.t
new file mode 100755 (executable)
index 0000000..31acc5a
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/sh
+# Check we can delete a key successfully with the file backend.
+
+set -e
+
+cd t
+../onak -b -c test.conf add < ../keys/noodles.key
+../onak -b -c test.conf delete 0x2DA8B985
+if [ -e db/0x2DA8B985 ]; then
+       echo "* Did not correctly delete key using file backend"
+       exit 1
+fi
+
+exit 0
diff --git a/t/fs-000-add.t b/t/fs-000-add.t
new file mode 100755 (executable)
index 0000000..c20231e
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/sh
+# Check we can add a key successfully with the fs backend.
+
+set -e
+
+cd t
+../onak -b -c test.conf add < ../keys/noodles.key
+if [ ! -e db/key/2D/A8/2DA8B985/94FA372B2DA8B985 ]; then
+       echo Did not correctly add key using fs backend.
+       exit 1
+fi
+
+exit 0
diff --git a/t/fs-010-del.t b/t/fs-010-del.t
new file mode 100755 (executable)
index 0000000..43fa7b0
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/sh
+# Check we can delete a key successfully with the fs backend.
+
+set -e
+
+cd t
+../onak -b -c test.conf add < ../keys/noodles.key
+../onak -b -c test.conf delete 0x2DA8B985
+if [ -e db/key/2D/A8/2DA8B985/94FA372B2DA8B985 ]; then
+       echo "* Did not correctly delete key using fs backend"
+       exit 1
+fi
+
+exit 0
diff --git a/t/test-in.conf b/t/test-in.conf
new file mode 100644 (file)
index 0000000..b5309a0
--- /dev/null
@@ -0,0 +1,8 @@
+pks_bin_dir DIR
+backends_dir DIR
+db_dir DIR/t/db/
+logfile onak.log
+loglevel 7
+use_keyd false
+this_site pgp-public-keys@localhost
+max_reply_keys 128