@@ -171,7 +171,6 @@ def stream_events(self, inputs, ew):
171
171
assert xml_compare (expected , found )
172
172
assert return_value != 0
173
173
174
-
175
174
def test_write_events (capsys ):
176
175
"""Check that passing an input definition and writing a couple events goes smoothly."""
177
176
@@ -217,6 +216,46 @@ def stream_events(self, inputs, ew):
217
216
assert xml_compare (expected , found )
218
217
219
218
219
+ def test_telemetry (capsys ):
220
+ """Check that writing telemetry goes smoothly."""
221
+
222
+ # Override abstract methods
223
+ class NewScript (Script ):
224
+ def get_scheme (self ):
225
+ return None
226
+
227
+ def stream_events (self , _inputs , ew ):
228
+ event = Event (
229
+ data = "Test" ,
230
+ )
231
+
232
+ ew .write_event (event )
233
+
234
+ script = NewScript ()
235
+ input_configuration = data_open ("data/conf_with_2_inputs.xml" )
236
+
237
+ event_writer = EventWriter (sys .stdout , sys .stderr )
238
+
239
+ with patch .object (Service , 'post' ) as patched_telemetry_post :
240
+ patched_telemetry_post .return_value = Mock (** PATCHED_TELEMETRY_RESPONSE )
241
+
242
+ return_value = script .run_script ([TEST_SCRIPT_PATH ], event_writer , input_configuration )
243
+
244
+ post_args , post_kwargs = patched_telemetry_post .call_args_list [0 ]
245
+
246
+ assert post_args == ('telemetry-metric/' ,)
247
+ assert post_kwargs == {
248
+ 'app' : None ,
249
+ 'body' : '{"type": "event", "component": "splunk-sdk-python", "data": {"version": "1.6.13"}, "optInRequired": 2}' ,
250
+ 'headers' : [('Content-Type' , 'application/json' )],
251
+ 'owner' : None ,
252
+ 'sharing' : None
253
+ }
254
+
255
+ output = capsys .readouterr ()
256
+ assert output .err == ""
257
+ assert return_value == 0
258
+
220
259
def test_service_property (capsys ):
221
260
""" Check that Script.service returns a valid Service instance as soon
222
261
as the stream_events method is called, but not before.
0 commit comments