summaryrefslogtreecommitdiff
path: root/perl/t/lib
diff options
context:
space:
mode:
authorRuss Allbery <rra@stanford.edu>2007-12-01 00:42:46 +0000
committerRuss Allbery <rra@stanford.edu>2007-12-01 00:42:46 +0000
commitc9948c8f68b11a1e897afe9c9f2dd2fcb6934f8d (patch)
treef15323beb5ceac6a2b81df8634f5f9f23ad239c8 /perl/t/lib
parent1e13c0c60c96dd1719e7c4c3931b4196c2b5bc61 (diff)
The wallet backend test suite now supports using a database other than
SQLite for testing. Also start a new Util.pm module for the test suite and move the contents sub into that module. More to follow.
Diffstat (limited to 'perl/t/lib')
-rw-r--r--perl/t/lib/Util.pm67
1 files changed, 67 insertions, 0 deletions
diff --git a/perl/t/lib/Util.pm b/perl/t/lib/Util.pm
new file mode 100644
index 0000000..6566ca4
--- /dev/null
+++ b/perl/t/lib/Util.pm
@@ -0,0 +1,67 @@
+# Util -- Utility class for wallet tests.
+# $Id$
+#
+# Written by Russ Allbery <rra@stanford.edu>
+# Copyright 2007 Board of Trustees, Leland Stanford Jr. University
+#
+# See LICENSE for licensing terms.
+
+package Util;
+require 5.006;
+
+use strict;
+use vars qw(@ISA @EXPORT $VERSION);
+
+use Wallet::Config;
+
+# This version should be increased on any code change to this module. Always
+# use two digits for the minor version with a leading zero if necessary so
+# that it will sort properly.
+$VERSION = '0.01';
+
+use Exporter ();
+@ISA = qw(Exporter);
+@EXPORT = qw(contents db_setup);
+
+##############################################################################
+# General utility functions
+##############################################################################
+
+# Returns the one-line contents of a file as a string, removing the newline.
+sub contents {
+ my ($file) = @_;
+ open (FILE, '<', $file) or die "cannot open $file: $!\n";
+ my $data = <FILE>;
+ close FILE;
+ chomp $data;
+ return $data;
+}
+
+##############################################################################
+# User test configuration
+##############################################################################
+
+# Set up the database configuration parameters. Use a local SQLite database
+# for testing by default, but support t/data/test.database as a configuration
+# file to use another database backend.
+sub db_setup {
+ if (-f 't/data/test.database') {
+ open (DB, '<', 't/data/test.database')
+ or die "cannot open t/data/test.database: $!";
+ my $driver = <DB>;
+ my $info = <DB>;
+ my $user = <DB>;
+ my $password = <DB>;
+ chomp ($driver, $info);
+ chomp $user if $user;
+ chomp $password if $password;
+ $Wallet::Config::DB_DRIVER = $driver;
+ $Wallet::Config::DB_INFO = $info;
+ $Wallet::Config::DB_USER = $user if $user;
+ $Wallet::Config::DB_PASSWORD = $password if $password;
+ } else {
+ $Wallet::Config::DB_DRIVER = 'SQLite';
+ $Wallet::Config::DB_INFO = 'wallet-db';
+ unlink 'wallet-db';
+ }
+}