The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!perl -T

# Verify to create object with no dbnames, to list which dbnames exist.
# Verify to create object with dbname and define collection

use strict;
use warnings;
use Test::More tests => 5;

BEGIN {
    use_ok('Catalyst::Model::MongoDB');
}

my $mongo = new_ok 'Catalyst::Model::MongoDB';

# See if a test database is available. Preferably one called 'test'.
my $testdb;
eval '
  my @dbs = $mongo->dbnames();
  if ( grep /^test$/, @dbs ) {
    ($testdb) = grep /^test$/, @dbs;
  } elsif ( grep /test/i, @dbs ) {
    ($testdb) = grep /test/i, @dbs;
  } else {
    $testdb = shift @dbs;
  }
';

# If there is a database available, make reference to a collection
#
SKIP: {
  skip 'No local database available for testing', 3 unless $testdb;
  my $db = new_ok( 'Catalyst::Model::MongoDB' =>[
    dbname => $testdb,
  ] );
  ok ( $db, "database name" );
  my $coll = $db->collection('test');
  ok ( $coll, "Collection name" );
};