On Thu, Oct 09, 2008 at 06:10:30PM +0100, Smylers wrote:
> Greg Sabino Mullane writes:
> 
> > > ... I suppose it could also be somewhat easy to try out a few series
> > > of basic/default credentials on localhost for engines like MySQL and
> > > Postgres, and try to setup a test database from there.
> > 
> > That sounds more interesting.
> 
> It sounds scary to me.  If I'm just installing a Perl module from Cpan
> on a newly installed OS, which happens to still have default DB
> connection permissions, I wouldn't expect the module's tests to start
> making use of the DB without asking.

Yes, I've been thinking a little more about it, and here's my current plan.

The Test::Database module will NOT try to find an existing database to
jump on. The risk of a test author wanting to connect to a named database
(think of obvious names like "clients", "business", "company", etc),
the module finding it and the database itself being a little too open
make it just scary for me.

So, the first thing it will do is find itself a nice place in
File::Spec->tmpdir(). Something like "$tmp/Test-Database-$username".

There will be a Test::Database::Driver for each supported database,
and the data for the temporary databases will live under
"$tmp/Test-Database-$username/$driver".

> Further, if the module install fails the database may be left behind.
> Which is going to be very surprising when I then connect to the DBMS and
> see there's already this weird database there.

By default, I intend to have a "setup" phase, which will create the
database if it doesn't exist yet, a "start" phase which will start the
database server (if needed), and a "stop" phase which will shut it down.

Yes, that means each script needing a database will automatically
startup and shutdown a database server. On the other hand, the data will
stay there from script to script.

I'll also provide a cleanup routine that will just rm -rf the test
database home. Probably something like perl -MTest::Database=cleanup -e1
will do.

If the database engine is installed, there are ways for an unprivileged
user to setup a db in a local directory and use that. At least there are 
for MySQL and Postgres. It might be a little harder with other engines,
which may make the whole "local configuration" setup still desirable.

> (Similarly, if a test needs an image, please don't just search users'
> home directories for one; if a test needs to send an e-mail, don't just
> look in the user's address book for somebody to mail.  Just cos a test
> is running as a user which has permission to do certain things outside
> the current directory doesn't mean it's reasonable for a test to do so.)

I fully agree with this view.

-- 
 Philippe Bruhat (BooK)

 We vote to pick our leaders-     /     And we place them in a tower-
 Why is it that we cannot wait-   /     To vote them out of power?
                                (Intro poem to Groo The Wanderer #109 (Epic))

Reply via email to