| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Test::Mock::Mango::Collection; |
|
2
|
|
|
|
|
|
|
|
|
3
|
19
|
|
|
19
|
|
193
|
use v5.10; |
|
|
19
|
|
|
|
|
63
|
|
|
|
19
|
|
|
|
|
882
|
|
|
4
|
19
|
|
|
19
|
|
99
|
use strict; |
|
|
19
|
|
|
|
|
29
|
|
|
|
19
|
|
|
|
|
527
|
|
|
5
|
19
|
|
|
19
|
|
93
|
use warnings; |
|
|
19
|
|
|
|
|
31
|
|
|
|
19
|
|
|
|
|
858
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
|
8
|
|
|
|
|
|
|
|
|
9
|
19
|
|
|
19
|
|
22284
|
use Test::Mock::Mango::Cursor; |
|
|
19
|
|
|
|
|
68
|
|
|
|
19
|
|
|
|
|
520
|
|
|
10
|
19
|
|
|
19
|
|
121
|
use Mango::BSON::ObjectID; |
|
|
19
|
|
|
|
|
38
|
|
|
|
19
|
|
|
|
|
217
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
|
15
|
45
|
|
|
45
|
0
|
4165
|
my $class = shift; |
|
16
|
45
|
|
|
|
|
83
|
my $name = $_[-1]; pop; |
|
|
45
|
|
|
|
|
60
|
|
|
17
|
45
|
|
|
|
|
69
|
my $db = shift; |
|
18
|
|
|
|
|
|
|
|
|
19
|
45
|
|
100
|
|
|
707
|
bless { |
|
20
|
|
|
|
|
|
|
name => $name, |
|
21
|
|
|
|
|
|
|
db => $db||undef, |
|
22
|
|
|
|
|
|
|
}, $class; |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# aggregate |
|
28
|
|
|
|
|
|
|
# |
|
29
|
|
|
|
|
|
|
# Fake an "aggregated result" by returning the current fake collection |
|
30
|
|
|
|
|
|
|
# |
|
31
|
|
|
|
|
|
|
sub aggregate { |
|
32
|
4
|
|
|
4
|
0
|
7
|
my $self = shift; |
|
33
|
4
|
100
|
|
|
|
15
|
my $cb = ref $_[-1] eq 'CODE' ? pop : undef; |
|
34
|
|
|
|
|
|
|
|
|
35
|
4
|
|
|
|
|
5
|
my $docs = undef; |
|
36
|
4
|
|
|
|
|
5
|
my $err = undef; |
|
37
|
|
|
|
|
|
|
|
|
38
|
4
|
100
|
|
|
|
10
|
if (defined $Test::Mock::Mango::error) { |
|
39
|
2
|
|
|
|
|
4
|
$err = $Test::Mock::Mango::error; |
|
40
|
2
|
|
|
|
|
4
|
$Test::Mock::Mango::error = undef; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
else { |
|
43
|
2
|
|
|
|
|
8
|
$docs = $Test::Mock::Mango::data->{collection}; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
4
|
100
|
|
|
|
17
|
return $cb->($self,$err,$docs) if $cb; |
|
47
|
2
|
|
|
|
|
6
|
return $docs; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# create |
|
53
|
|
|
|
|
|
|
# |
|
54
|
|
|
|
|
|
|
# Doesn't do anything. Just return with or without error as specified |
|
55
|
|
|
|
|
|
|
# |
|
56
|
|
|
|
|
|
|
sub create { |
|
57
|
2
|
|
|
2
|
0
|
3
|
my $self = shift; |
|
58
|
2
|
50
|
|
|
|
9
|
my $cb = ref $_[-1] eq 'CODE' ? pop : undef; |
|
59
|
|
|
|
|
|
|
|
|
60
|
2
|
|
|
|
|
3
|
my $err = undef; |
|
61
|
2
|
100
|
|
|
|
9
|
if (defined $Test::Mock::Mango::error) { |
|
62
|
1
|
|
|
|
|
2
|
$err = $Test::Mock::Mango::error; |
|
63
|
1
|
|
|
|
|
2
|
$Test::Mock::Mango::error = undef; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
2
|
50
|
|
|
|
10
|
return $cb->($self,$err) if $cb; |
|
67
|
0
|
|
|
|
|
0
|
return; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# drop |
|
73
|
|
|
|
|
|
|
# |
|
74
|
|
|
|
|
|
|
# Doesn't do anything. Just return with or without error as specified |
|
75
|
|
|
|
|
|
|
# |
|
76
|
|
|
|
|
|
|
sub drop { |
|
77
|
2
|
|
|
2
|
0
|
26
|
my $self = shift; |
|
78
|
2
|
50
|
|
|
|
6
|
my $cb = ref $_[-1] eq 'CODE' ? pop : undef; |
|
79
|
|
|
|
|
|
|
|
|
80
|
2
|
|
|
|
|
2
|
my $err = undef; |
|
81
|
2
|
100
|
|
|
|
9
|
if (defined $Test::Mock::Mango::error) { |
|
82
|
1
|
|
|
|
|
2
|
$err = $Test::Mock::Mango::error; |
|
83
|
1
|
|
|
|
|
2
|
$Test::Mock::Mango::error = undef; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
2
|
50
|
|
|
|
11
|
return $cb->($self,$err) if $cb; |
|
87
|
0
|
|
|
|
|
0
|
return; |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# find_one |
|
93
|
|
|
|
|
|
|
# |
|
94
|
|
|
|
|
|
|
# By default we return the first document from the fake data collection |
|
95
|
|
|
|
|
|
|
# |
|
96
|
|
|
|
|
|
|
sub find_one { |
|
97
|
5
|
|
|
5
|
0
|
10
|
my ($self, $query) = (shift,shift); |
|
98
|
|
|
|
|
|
|
|
|
99
|
5
|
100
|
|
|
|
14
|
my $cb = ref $_[-1] eq 'CODE' ? pop : undef; |
|
100
|
5
|
|
|
|
|
7
|
my $doc = undef; |
|
101
|
5
|
|
|
|
|
4
|
my $err = undef; |
|
102
|
|
|
|
|
|
|
|
|
103
|
5
|
100
|
|
|
|
11
|
if (defined $Test::Mock::Mango::error) { |
|
104
|
2
|
|
|
|
|
4
|
$err = $Test::Mock::Mango::error; |
|
105
|
2
|
|
|
|
|
3
|
$Test::Mock::Mango::error = undef; |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
else { |
|
108
|
|
|
|
|
|
|
# Return the first fake document |
|
109
|
3
|
|
100
|
|
|
18
|
$doc = $Test::Mock::Mango::data->{collection}->[0] || undef; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
5
|
100
|
|
|
|
19
|
return $cb->($self, $err, $doc) if $cb; # Non blocking |
|
113
|
3
|
|
|
|
|
8
|
return $doc; # Blocking |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# find |
|
119
|
|
|
|
|
|
|
# |
|
120
|
|
|
|
|
|
|
# returns a new fake cursor |
|
121
|
|
|
|
|
|
|
# |
|
122
|
|
|
|
|
|
|
sub find { |
|
123
|
1
|
|
|
1
|
0
|
11
|
return Test::Mock::Mango::Cursor->new; # Not actually passing any values |
|
124
|
|
|
|
|
|
|
# through as we're not using them :-p |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# full_name |
|
130
|
|
|
|
|
|
|
# |
|
131
|
|
|
|
|
|
|
# returns a concat of db.collection |
|
132
|
|
|
|
|
|
|
# |
|
133
|
|
|
|
|
|
|
sub full_name { |
|
134
|
2
|
|
|
2
|
0
|
55
|
my ($self) = @_; |
|
135
|
2
|
|
100
|
|
|
27
|
my $db = $self->{db}||{name=>undef}; |
|
136
|
|
|
|
|
|
|
|
|
137
|
2
|
|
|
|
|
8
|
my $name = $db->{name}; |
|
138
|
2
|
100
|
|
|
|
10
|
$name .= $name ? '.' : ''; |
|
139
|
2
|
|
|
|
|
7
|
$name .= $self->{name}; |
|
140
|
|
|
|
|
|
|
|
|
141
|
2
|
|
|
|
|
17
|
return $name; |
|
142
|
|
|
|
|
|
|
} |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub insert { |
|
147
|
8
|
|
|
8
|
0
|
13
|
my ($self, $docs) = (shift,shift); |
|
148
|
|
|
|
|
|
|
|
|
149
|
8
|
100
|
|
|
|
23
|
my $cb = ref $_[-1] eq 'CODE' ? pop : undef; |
|
150
|
|
|
|
|
|
|
|
|
151
|
8
|
|
|
|
|
14
|
my $oids = []; |
|
152
|
8
|
|
|
|
|
12
|
my $err = undef; |
|
153
|
8
|
|
|
|
|
11
|
my $return_oids = ''; |
|
154
|
|
|
|
|
|
|
|
|
155
|
8
|
100
|
|
|
|
18
|
if (defined $Test::Mock::Mango::error) { |
|
156
|
2
|
|
|
|
|
3
|
$return_oids = undef; |
|
157
|
2
|
|
|
|
|
4
|
$err = $Test::Mock::Mango::error; |
|
158
|
2
|
|
|
|
|
3
|
$Test::Mock::Mango::error = undef; |
|
159
|
|
|
|
|
|
|
} |
|
160
|
|
|
|
|
|
|
else { |
|
161
|
|
|
|
|
|
|
# Get how many docs we're "inserting" so we can return the right number of oids |
|
162
|
6
|
|
|
|
|
9
|
my $num_docs = 1; |
|
163
|
6
|
100
|
|
|
|
13
|
if (ref $docs eq 'ARRAY') { |
|
164
|
2
|
|
|
|
|
5
|
$num_docs = scalar @$docs; |
|
165
|
2
|
|
|
|
|
9
|
for (0..$num_docs-1) { |
|
166
|
4
|
|
66
|
|
|
39
|
push @$oids, $docs->[$_]->{_id} // Mango::BSON::ObjectID->new; |
|
167
|
4
|
|
|
|
|
46
|
push @{$Test::Mock::Mango::data->{collection}}, $docs->[$_]; |
|
|
4
|
|
|
|
|
19
|
|
|
168
|
|
|
|
|
|
|
} |
|
169
|
2
|
|
|
|
|
5
|
$return_oids = $oids; |
|
170
|
|
|
|
|
|
|
} |
|
171
|
|
|
|
|
|
|
else { |
|
172
|
4
|
|
66
|
|
|
34
|
push @$oids, $docs->{_id} // Mango::BSON::ObjectID->new; |
|
173
|
4
|
|
|
|
|
115
|
push @{$Test::Mock::Mango::data->{collection}}, $docs; |
|
|
4
|
|
|
|
|
15
|
|
|
174
|
4
|
|
|
|
|
8
|
$return_oids = $oids->[0]; |
|
175
|
|
|
|
|
|
|
} |
|
176
|
|
|
|
|
|
|
} |
|
177
|
|
|
|
|
|
|
|
|
178
|
8
|
100
|
|
|
|
26
|
return $cb->($self,$err,$return_oids) if $cb; |
|
179
|
4
|
|
|
|
|
15
|
return $return_oids; |
|
180
|
|
|
|
|
|
|
} |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
sub remove { |
|
185
|
6
|
|
|
6
|
0
|
7
|
my $self = shift; |
|
186
|
6
|
50
|
50
|
|
|
27
|
my $query = ref $_[0] eq 'CODE' ? {} : shift // {}; |
|
187
|
6
|
100
|
50
|
|
|
28
|
my $flags = ref $_[0] eq 'CODE' ? {} : shift // {}; |
|
188
|
|
|
|
|
|
|
|
|
189
|
6
|
100
|
|
|
|
13
|
my $cb = ref $_[-1] eq 'CODE' ? pop : undef; |
|
190
|
|
|
|
|
|
|
|
|
191
|
6
|
|
|
|
|
7
|
my $doc = undef; # TODO What should this return? |
|
192
|
6
|
|
|
|
|
7
|
my $err = undef; |
|
193
|
|
|
|
|
|
|
|
|
194
|
6
|
100
|
|
|
|
11
|
if (defined $Test::Mock::Mango::error) { |
|
195
|
2
|
|
|
|
|
4
|
$err = $Test::Mock::Mango::error; |
|
196
|
2
|
|
|
|
|
4
|
$Test::Mock::Mango::error = undef; |
|
197
|
|
|
|
|
|
|
} |
|
198
|
|
|
|
|
|
|
else { |
|
199
|
4
|
|
100
|
|
|
19
|
$doc->{n} = $Test::Mock::Mango::n // 1; |
|
200
|
|
|
|
|
|
|
} |
|
201
|
|
|
|
|
|
|
|
|
202
|
6
|
|
|
|
|
16
|
$Test::Mock::Mango::n = undef; |
|
203
|
|
|
|
|
|
|
|
|
204
|
6
|
100
|
|
|
|
16
|
return $cb->($self,$err,$doc) if $cb; |
|
205
|
4
|
|
|
|
|
12
|
return $doc; |
|
206
|
|
|
|
|
|
|
} |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
sub update { |
|
211
|
6
|
|
|
6
|
0
|
16
|
my ($self,$query,$changes) = (shift,shift,shift); |
|
212
|
|
|
|
|
|
|
|
|
213
|
6
|
100
|
|
|
|
83
|
my $cb = ref $_[-1] eq 'CODE' ? pop : undef; |
|
214
|
|
|
|
|
|
|
|
|
215
|
6
|
|
|
|
|
11
|
my $err = undef; |
|
216
|
6
|
|
|
|
|
9
|
my $doc = undef; |
|
217
|
|
|
|
|
|
|
|
|
218
|
6
|
100
|
|
|
|
18
|
if (defined $Test::Mock::Mango::error) { |
|
219
|
2
|
|
|
|
|
4
|
$err = $Test::Mock::Mango::error; |
|
220
|
2
|
|
|
|
|
3
|
$Test::Mock::Mango::error = undef; |
|
221
|
|
|
|
|
|
|
} |
|
222
|
|
|
|
|
|
|
else { |
|
223
|
4
|
|
|
|
|
9
|
$doc = $changes; |
|
224
|
4
|
|
100
|
|
|
30
|
$doc->{n} = $Test::Mock::Mango::n // 1; |
|
225
|
|
|
|
|
|
|
} |
|
226
|
|
|
|
|
|
|
|
|
227
|
6
|
|
|
|
|
13
|
$Test::Mock::Mango::n = undef; |
|
228
|
|
|
|
|
|
|
|
|
229
|
6
|
100
|
|
|
|
24
|
return $cb->($self,$err,$doc) if $cb; |
|
230
|
4
|
|
|
|
|
14
|
return $doc; |
|
231
|
|
|
|
|
|
|
} |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
sub find_and_modify { |
|
236
|
5
|
|
|
5
|
0
|
8
|
my ($self, $opts) = (shift,shift); |
|
237
|
|
|
|
|
|
|
|
|
238
|
5
|
100
|
|
|
|
15
|
my $cb = ref $_[-1] eq 'CODE' ? pop : undef; |
|
239
|
5
|
|
|
|
|
6
|
my $doc = undef; |
|
240
|
5
|
|
|
|
|
6
|
my $err = undef; |
|
241
|
|
|
|
|
|
|
|
|
242
|
5
|
100
|
|
|
|
13
|
if (defined $Test::Mock::Mango::error) { |
|
243
|
2
|
|
|
|
|
3
|
$err = $Test::Mock::Mango::error; |
|
244
|
2
|
|
|
|
|
4
|
$Test::Mock::Mango::error = undef; |
|
245
|
|
|
|
|
|
|
} |
|
246
|
|
|
|
|
|
|
else { |
|
247
|
|
|
|
|
|
|
# Return the first fake document |
|
248
|
3
|
|
100
|
|
|
23
|
$doc = $Test::Mock::Mango::data->{collection}->[0] || undef; |
|
249
|
|
|
|
|
|
|
} |
|
250
|
|
|
|
|
|
|
|
|
251
|
5
|
100
|
|
|
|
17
|
return $cb->($self, $err, $doc) if $cb; # Non blocking |
|
252
|
3
|
|
|
|
|
9
|
return $doc; # Blocking |
|
253
|
|
|
|
|
|
|
} |
|
254
|
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
|
256
|
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
1; |
|
258
|
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=encoding utf8 |
|
260
|
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=head1 NAME |
|
262
|
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
Test::Mock::Mango::Collection - fake Mango::Collection |
|
264
|
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
266
|
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
Simulated mango collection for unit testing as part of L. |
|
268
|
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=cut |