@@ -36,12 +36,22 @@ def discard_spans!
36
36
# Clear data between tests
37
37
let ( :drop_database? ) { true }
38
38
39
+ def suppress_warnings
40
+ original_verbosity = $VERBOSE
41
+ $VERBOSE = nil
42
+ yield
43
+ ensure
44
+ $VERBOSE = original_verbosity
45
+ end
46
+
39
47
around do |example |
40
- # Reset before and after each example; don't allow global state to linger.
41
- Datadog . registry [ :mongo ] . reset_configuration!
42
- example . run
43
- Datadog . registry [ :mongo ] . reset_configuration!
44
- client . database . drop if drop_database?
48
+ suppress_warnings do
49
+ # Reset before and after each example; don't allow global state to linger.
50
+ Datadog . registry [ :mongo ] . reset_configuration!
51
+ example . run
52
+ Datadog . registry [ :mongo ] . reset_configuration!
53
+ client . database . drop if drop_database?
54
+ end
45
55
end
46
56
47
57
it 'evaluates the block given to the constructor' do
@@ -89,6 +99,14 @@ def discard_spans!
89
99
end
90
100
end
91
101
102
+ RSpec ::Matchers . define :eq_serialized_operation do |expected |
103
+ match do |actual |
104
+ actual_obj = actual . is_a? ( String ) ? JSON . parse ( actual . gsub ( /=>/ , ':' ) ) : actual
105
+ expected_obj = expected . is_a? ( String ) ? JSON . parse ( expected . gsub ( /=>/ , ':' ) ) : expected
106
+ expect ( expected_obj ) . to eq ( actual_obj )
107
+ end
108
+ end
109
+
92
110
describe '#insert_one operation' do
93
111
before ( :each ) { client [ collection ] . insert_one ( params ) }
94
112
@@ -101,7 +119,7 @@ def discard_spans!
101
119
if mongo_gem_version < Gem ::Version . new ( '2.5' )
102
120
expect ( span . resource ) . to eq ( "{\" operation\" =>:insert, \" database\" =>\" #{ database } \" , \" collection\" =>\" #{ collection } \" , \" documents\" =>[{:name=>\" ?\" }], \" ordered\" =>\" ?\" }" )
103
121
else
104
- expect ( span . resource ) . to eq ( "{\" operation\" =>\" insert\" , \" database\" =>\" #{ database } \" , \" collection\" =>\" #{ collection } \" , \" ordered\" =>\" ?\" , \" lsid\" =>{\" id\" =>\" ?\" }, \" documents\" =>[{\" name\" =>\" ?\" }]}" )
122
+ expect ( span . resource ) . to eq_serialized_operation ( "{\" operation\" =>\" insert\" , \" database\" =>\" #{ database } \" , \" collection\" =>\" #{ collection } \" , \" ordered\" =>\" ?\" , \" lsid\" =>{\" id\" =>\" ?\" }, \" documents\" =>[{\" name\" =>\" ?\" }]}" )
105
123
end
106
124
expect ( span . get_tag ( 'mongodb.rows' ) ) . to eq ( '1' )
107
125
end
@@ -117,7 +135,7 @@ def discard_spans!
117
135
if mongo_gem_version < Gem ::Version . new ( '2.5' )
118
136
expect ( span . resource ) . to eq ( "{\" operation\" =>:insert, \" database\" =>\" #{ database } \" , \" collection\" =>\" #{ collection } \" , \" documents\" =>[{:name=>\" ?\" , :hobbies=>[\" ?\" ]}], \" ordered\" =>\" ?\" }" )
119
137
else
120
- expect ( span . resource ) . to eq ( "{\" operation\" =>\" insert\" , \" database\" =>\" #{ database } \" , \" collection\" =>\" #{ collection } \" , \" ordered\" =>\" ?\" , \" lsid\" =>{\" id\" =>\" ?\" }, \" documents\" =>[{\" name\" =>\" ?\" , \" hobbies\" =>[\" ?\" ]}]}" )
138
+ expect ( span . resource ) . to eq_serialized_operation ( "{\" operation\" =>\" insert\" , \" database\" =>\" #{ database } \" , \" collection\" =>\" #{ collection } \" , \" ordered\" =>\" ?\" , \" lsid\" =>{\" id\" =>\" ?\" }, \" documents\" =>[{\" name\" =>\" ?\" , \" hobbies\" =>[\" ?\" ]}]}" )
121
139
end
122
140
expect ( span . get_tag ( 'mongodb.rows' ) ) . to eq ( '1' )
123
141
end
@@ -143,7 +161,7 @@ def discard_spans!
143
161
if mongo_gem_version < Gem ::Version . new ( '2.5' )
144
162
expect ( span . resource ) . to eq ( "{\" operation\" =>:insert, \" database\" =>\" #{ database } \" , \" collection\" =>\" #{ collection } \" , \" documents\" =>[{:name=>\" ?\" , :hobbies=>[\" ?\" ]}, \" ?\" ], \" ordered\" =>\" ?\" }" )
145
163
else
146
- expect ( span . resource ) . to eq ( "{\" operation\" =>\" insert\" , \" database\" =>\" #{ database } \" , \" collection\" =>\" #{ collection } \" , \" ordered\" =>\" ?\" , \" lsid\" =>{\" id\" =>\" ?\" }, \" documents\" =>[{\" name\" =>\" ?\" , \" hobbies\" =>[\" ?\" ]}, \" ?\" ]}" )
164
+ expect ( span . resource ) . to eq_serialized_operation ( "{\" operation\" =>\" insert\" , \" database\" =>\" #{ database } \" , \" collection\" =>\" #{ collection } \" , \" ordered\" =>\" ?\" , \" lsid\" =>{\" id\" =>\" ?\" }, \" documents\" =>[{\" name\" =>\" ?\" , \" hobbies\" =>[\" ?\" ]}, \" ?\" ]}" )
147
165
end
148
166
expect ( span . get_tag ( 'mongodb.rows' ) ) . to eq ( '2' )
149
167
end
@@ -170,7 +188,7 @@ def discard_spans!
170
188
if mongo_gem_version < Gem ::Version . new ( '2.5' )
171
189
expect ( span . resource ) . to eq ( "{\" operation\" =>\" find\" , \" database\" =>\" #{ database } \" , \" collection\" =>\" #{ collection } \" , \" filter\" =>{}}" )
172
190
else
173
- expect ( span . resource ) . to eq ( "{\" operation\" =>\" find\" , \" database\" =>\" #{ database } \" , \" collection\" =>\" #{ collection } \" , \" filter\" =>{}, \" lsid\" =>{\" id\" =>\" ?\" }}" )
191
+ expect ( span . resource ) . to eq_serialized_operation ( "{\" operation\" =>\" find\" , \" database\" =>\" #{ database } \" , \" collection\" =>\" #{ collection } \" , \" filter\" =>{}, \" lsid\" =>{\" id\" =>\" ?\" }}" )
174
192
end
175
193
expect ( span . get_tag ( 'mongodb.rows' ) ) . to be nil
176
194
end
@@ -195,7 +213,7 @@ def discard_spans!
195
213
if mongo_gem_version < Gem ::Version . new ( '2.5' )
196
214
expect ( span . resource ) . to eq ( "{\" operation\" =>\" find\" , \" database\" =>\" #{ database } \" , \" collection\" =>\" #{ collection } \" , \" filter\" =>{\" name\" =>\" ?\" }}" )
197
215
else
198
- expect ( span . resource ) . to eq ( "{\" operation\" =>\" find\" , \" database\" =>\" #{ database } \" , \" collection\" =>\" #{ collection } \" , \" filter\" =>{\" name\" =>\" ?\" }, \" lsid\" =>{\" id\" =>\" ?\" }}" )
216
+ expect ( span . resource ) . to eq_serialized_operation ( "{\" operation\" =>\" find\" , \" database\" =>\" #{ database } \" , \" collection\" =>\" #{ collection } \" , \" filter\" =>{\" name\" =>\" ?\" }, \" lsid\" =>{\" id\" =>\" ?\" }}" )
199
217
end
200
218
expect ( span . get_tag ( 'mongodb.rows' ) ) . to be nil
201
219
end
@@ -224,7 +242,7 @@ def discard_spans!
224
242
if mongo_gem_version < Gem ::Version . new ( '2.5' )
225
243
expect ( span . resource ) . to eq ( "{\" operation\" =>:update, \" database\" =>\" #{ database } \" , \" collection\" =>\" #{ collection } \" , \" updates\" =>[{\" q\" =>{\" name\" =>\" ?\" }, \" u\" =>{\" $set\" =>{\" phone_number\" =>\" ?\" }}, \" multi\" =>\" ?\" , \" upsert\" =>\" ?\" }], \" ordered\" =>\" ?\" }" )
226
244
else
227
- expect ( span . resource ) . to eq ( "{\" operation\" =>\" update\" , \" database\" =>\" #{ database } \" , \" collection\" =>\" #{ collection } \" , \" ordered\" =>\" ?\" , \" lsid\" =>{\" id\" =>\" ?\" }, \" updates\" =>[{\" q\" =>{\" name\" =>\" ?\" }, \" u\" =>{\" $set\" =>{\" phone_number\" =>\" ?\" }}, \" multi\" =>\" ?\" , \" upsert\" =>\" ?\" }]}" )
245
+ expect ( span . resource ) . to eq_serialized_operation ( "{\" operation\" =>\" update\" , \" database\" =>\" #{ database } \" , \" collection\" =>\" #{ collection } \" , \" ordered\" =>\" ?\" , \" lsid\" =>{\" id\" =>\" ?\" }, \" updates\" =>[{\" q\" =>{\" name\" =>\" ?\" }, \" u\" =>{\" $set\" =>{\" phone_number\" =>\" ?\" }}, \" multi\" =>\" ?\" , \" upsert\" =>\" ?\" }]}" )
228
246
end
229
247
expect ( span . get_tag ( 'mongodb.rows' ) ) . to eq ( '1' )
230
248
end
@@ -261,7 +279,7 @@ def discard_spans!
261
279
if mongo_gem_version < Gem ::Version . new ( '2.5' )
262
280
expect ( span . resource ) . to eq ( "{\" operation\" =>:update, \" database\" =>\" #{ database } \" , \" collection\" =>\" #{ collection } \" , \" updates\" =>[{\" q\" =>{}, \" u\" =>{\" $set\" =>{\" phone_number\" =>\" ?\" }}, \" multi\" =>\" ?\" , \" upsert\" =>\" ?\" }], \" ordered\" =>\" ?\" }" )
263
281
else
264
- expect ( span . resource ) . to eq ( "{\" operation\" =>\" update\" , \" database\" =>\" #{ database } \" , \" collection\" =>\" #{ collection } \" , \" ordered\" =>\" ?\" , \" lsid\" =>{\" id\" =>\" ?\" }, \" updates\" =>[{\" q\" =>{}, \" u\" =>{\" $set\" =>{\" phone_number\" =>\" ?\" }}, \" multi\" =>\" ?\" , \" upsert\" =>\" ?\" }]}" )
282
+ expect ( span . resource ) . to eq_serialized_operation ( "{\" operation\" =>\" update\" , \" database\" =>\" #{ database } \" , \" collection\" =>\" #{ collection } \" , \" ordered\" =>\" ?\" , \" lsid\" =>{\" id\" =>\" ?\" }, \" updates\" =>[{\" q\" =>{}, \" u\" =>{\" $set\" =>{\" phone_number\" =>\" ?\" }}, \" multi\" =>\" ?\" , \" upsert\" =>\" ?\" }]}" )
265
283
end
266
284
expect ( span . get_tag ( 'mongodb.rows' ) ) . to eq ( '2' )
267
285
end
@@ -290,7 +308,7 @@ def discard_spans!
290
308
if mongo_gem_version < Gem ::Version . new ( '2.5' )
291
309
expect ( span . resource ) . to eq ( "{\" operation\" =>:delete, \" database\" =>\" #{ database } \" , \" collection\" =>\" #{ collection } \" , \" deletes\" =>[{\" q\" =>{\" name\" =>\" ?\" }, \" limit\" =>\" ?\" }], \" ordered\" =>\" ?\" }" )
292
310
else
293
- expect ( span . resource ) . to eq ( "{\" operation\" =>\" delete\" , \" database\" =>\" #{ database } \" , \" collection\" =>\" #{ collection } \" , \" ordered\" =>\" ?\" , \" lsid\" =>{\" id\" =>\" ?\" }, \" deletes\" =>[{\" q\" =>{\" name\" =>\" ?\" }, \" limit\" =>\" ?\" }]}" )
311
+ expect ( span . resource ) . to eq_serialized_operation ( "{\" operation\" =>\" delete\" , \" database\" =>\" #{ database } \" , \" collection\" =>\" #{ collection } \" , \" ordered\" =>\" ?\" , \" lsid\" =>{\" id\" =>\" ?\" }, \" deletes\" =>[{\" q\" =>{\" name\" =>\" ?\" }, \" limit\" =>\" ?\" }]}" )
294
312
end
295
313
expect ( span . get_tag ( 'mongodb.rows' ) ) . to eq ( '1' )
296
314
end
@@ -327,7 +345,7 @@ def discard_spans!
327
345
if mongo_gem_version < Gem ::Version . new ( '2.5' )
328
346
expect ( span . resource ) . to eq ( "{\" operation\" =>:delete, \" database\" =>\" #{ database } \" , \" collection\" =>\" #{ collection } \" , \" deletes\" =>[{\" q\" =>{\" name\" =>\" ?\" }, \" limit\" =>\" ?\" }], \" ordered\" =>\" ?\" }" )
329
347
else
330
- expect ( span . resource ) . to eq ( "{\" operation\" =>\" delete\" , \" database\" =>\" #{ database } \" , \" collection\" =>\" #{ collection } \" , \" ordered\" =>\" ?\" , \" lsid\" =>{\" id\" =>\" ?\" }, \" deletes\" =>[{\" q\" =>{\" name\" =>\" ?\" }, \" limit\" =>\" ?\" }]}" )
348
+ expect ( span . resource ) . to eq_serialized_operation ( "{\" operation\" =>\" delete\" , \" database\" =>\" #{ database } \" , \" collection\" =>\" #{ collection } \" , \" ordered\" =>\" ?\" , \" lsid\" =>{\" id\" =>\" ?\" }, \" deletes\" =>[{\" q\" =>{\" name\" =>\" ?\" }, \" limit\" =>\" ?\" }]}" )
331
349
end
332
350
expect ( span . get_tag ( 'mongodb.rows' ) ) . to eq ( '2' )
333
351
end
@@ -344,7 +362,7 @@ def discard_spans!
344
362
if mongo_gem_version < Gem ::Version . new ( '2.5' )
345
363
expect ( span . resource ) . to eq ( "{\" operation\" =>:dropDatabase, \" database\" =>\" #{ database } \" , \" collection\" =>1}" )
346
364
else
347
- expect ( span . resource ) . to eq ( "{\" operation\" =>\" dropDatabase\" , \" database\" =>\" #{ database } \" , \" collection\" =>1, \" lsid\" =>{\" id\" =>\" ?\" }}" )
365
+ expect ( span . resource ) . to eq_serialized_operation ( "{\" operation\" =>\" dropDatabase\" , \" database\" =>\" #{ database } \" , \" collection\" =>1, \" lsid\" =>{\" id\" =>\" ?\" }}" )
348
366
end
349
367
expect ( span . get_tag ( 'mongodb.rows' ) ) . to be nil
350
368
end
@@ -359,7 +377,7 @@ def discard_spans!
359
377
if mongo_gem_version < Gem ::Version . new ( '2.5' )
360
378
expect ( span . resource ) . to eq ( "{\" operation\" =>:drop, \" database\" =>\" #{ database } \" , \" collection\" =>\" #{ collection } \" }" )
361
379
else
362
- expect ( span . resource ) . to eq ( "{\" operation\" =>\" drop\" , \" database\" =>\" #{ database } \" , \" collection\" =>\" #{ collection } \" , \" lsid\" =>{\" id\" =>\" ?\" }}" )
380
+ expect ( span . resource ) . to eq_serialized_operation ( "{\" operation\" =>\" drop\" , \" database\" =>\" #{ database } \" , \" collection\" =>\" #{ collection } \" , \" lsid\" =>{\" id\" =>\" ?\" }}" )
363
381
end
364
382
expect ( span . get_tag ( 'mongodb.rows' ) ) . to be nil
365
383
expect ( span . status ) . to eq ( 1 )
0 commit comments