File: 15-import.t

package info (click to toggle)
libtest-mock-redis-perl 0.22-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 224 kB
  • sloc: perl: 2,239; makefile: 2
file content (55 lines) | stat: -rwxr-xr-x 1,357 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env perl

use strict;
use warnings;
use Test::More;
use Test::Fatal 'exception';
use Test::Deep;
use Test::Mock::Redis ();

#
# first demonstrate failure
#
my $r1 = Test::Mock::Redis->new(server => '1.1.1.1:1111');

like exception { $r1->select(19) }, qr/\QYou called select(19), but max allowed is 15/;


#
# now change the setting
#
# the equivalent of 'use $class num_databases => 20'
Test::Mock::Redis->import(num_databases => 20);

# need a different server since the first one is already set up in $instances
my $r2 = Test::Mock::Redis->new(server => '2.2.2.2:2222');
$r2->set('key-in-default-db-0', 'foobar');

# now this will pass
is exception { $r2->select(19) }, undef;

# and this won't include key-in-default-db-0
$r2->set('key1', 'foobar');
$r2->set('key2', 'foobar');
cmp_deeply( [ $r2->keys('*') ], bag('key1', 'key2'));


#
# allow alternate syntax, a method that says what it does, if the user wants
# to change it during the run of the test
#
Test::Mock::Redis::change_num_databases(30);
my $r3 = Test::Mock::Redis->new(server => '3.3.3.3:3333');
$r3->set('key-in-default-db-0', 'foobar');

# now this will pass
is exception { $r3->select(29) }, undef;

# and this won't include key-in-default-db-0
$r3->set('key1', 'foobar');
$r3->set('key2', 'foobar');
cmp_deeply( [ $r3->keys('*') ], bag('key1', 'key2'));

done_testing();