this repo has no description
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 test_with_database : Tests(1) {
30 return "MongoDB::Database not installed"
31 unless can_load( modules => { "MongoDB::Database" => undef } );
32
33 my $self = shift;
34 my $cache = CHI->new(
35 driver => "MongoDB",
36 db => $self->db
37 );
38
39 my $t = time;
40 $cache->set( "test", $t );
41 is( $cache->get("test"), $t );
42}
43
44sub test_with_connection : Tests(1) {
45 return "MongoDB::Connection not installed"
46 unless can_load( modules => { "MongoDB::Connection" => undef } );
47
48 my $self = shift;
49 my $cache = CHI->new(
50 driver => "MongoDB",
51 conn => MongoDB::Connection->new,
52 db_name => 't_chi_driver_mongodb',
53 );
54
55 my $t = time;
56 $cache->set( "test", $t );
57 is( $cache->get("test"), $t );
58}
59
60sub cleanup : Tests( shutdown ) {
61 my $self = shift;
62
63 my $cache = $self->db->drop;
64}
65
661;