On Wed, Oct 08, 2008 at 10:56:27AM +0200, Philippe Bruhat (BooK) wrote:

> Is there any way for a test suite to use the preferred database of a
> tester? Something like a TEST_DATABASE_DSN, TEST_DATABASE_USERNAME,
> TEST_DATABASE_PASSWORD triplet that CPAN testers could set to enable
> testing on different databases?
> 
> A colleague of mine is working on a very interesting module, but even
> though he could release a test suite relying on sqlite, I thought it
> would be better to use any configured database that was available on the
> tester's system.
> 
> Is there a recommended way to do that?

If you use a pre-existing database, you risk polluting your tests with
any rubbish that's already in there - perhaps left behind by the
previous module to be tested.  So I recommend creating a new database
for your tests, and clearing up afterwards.

This is easy for SQLite - just use File::Temp:
  
http://search.cpan.org/src/DCANTRELL/Class-DBI-ClassGenerator-1.01/t/sqlite_create_db.pl

For MySQL it's a little more involved, but only a little bit:
  http://search.cpan.org/src/DCANTRELL/Class-DBI-ClassGenerator-1.01/t/mysql.t
  
http://search.cpan.org/src/DCANTRELL/Class-DBI-ClassGenerator-1.01/t/mysql_create_db.pl

I've not (yet) bothered with PG, Oracle etc.  When I need them, I'll
probably extract it out into a nice neat Test::something module with a
bunch of database-specific back-ends.

-- 
David Cantrell | Nth greatest programmer in the world

  NANOG makes me want to unplug everything and hide under the bed
    -- brian d foy

Reply via email to