this repo has no description
at main 1.6 kB view raw
1package CHI::Driver::MongoDB::t::CHIDriverTests::MongoDB; 2 3use MongoDB; 4use Module::Load::Conditional qw(can_load); 5use Test::More; 6use strict; 7use warnings; 8use base qw(CHI::t::Driver); 9 10sub testing_driver_class { 'CHI::Driver::MongoDB' } 11sub supports_get_namespaces { 1 } 12 13sub SKIP_CLASS { 14 my $class = shift; 15 16 if ( not $class->db() ) { 17 return "Unable to get database connection."; 18 } 19 20 return 0; 21} 22 23sub db { 24 eval { 25 return MongoDB::Connection->new()->get_database('t_chi_driver_mongodb'); 26 }; 27} 28 29sub new_cache_options { 30 my $self = shift; 31 32 return ( 33 $self->SUPER::new_cache_options(), 34 db => $self->db, 35 ); 36} 37 38sub test_with_database : Tests(1) { 39 return "MongoDB::Database not installed" 40 unless can_load( modules => { "MongoDB::Database" => undef } ); 41 42 my $self = shift; 43 my $cache = CHI->new( 44 driver => "MongoDB", 45 db => $self->db 46 ); 47 48 my $t = time; 49 $cache->set( "test", $t ); 50 is( $cache->get("test"), $t ); 51} 52 53sub test_with_connection : Tests(1) { 54 return "MongoDB::Connection not installed" 55 unless can_load( modules => { "MongoDB::Connection" => undef } ); 56 57 my $self = shift; 58 my $cache = CHI->new( 59 driver => "MongoDB", 60 conn => MongoDB::Connection->new, 61 db_name => 't_chi_driver_mongodb', 62 ); 63 64 my $t = time; 65 $cache->set( "test", $t ); 66 is( $cache->get("test"), $t ); 67} 68 69sub cleanup : Tests( shutdown ) { 70 my $self = shift; 71 72 my $cache = $self->db->drop; 73} 74 751;