Skip to content

Commit f251ade

Browse files
committed
Telemetry args test
1 parent 37b01d1 commit f251ade

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

tests/modularinput/test_script.py

+40-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ def stream_events(self, inputs, ew):
171171
assert xml_compare(expected, found)
172172
assert return_value != 0
173173

174-
175174
def test_write_events(capsys):
176175
"""Check that passing an input definition and writing a couple events goes smoothly."""
177176

@@ -217,6 +216,46 @@ def stream_events(self, inputs, ew):
217216
assert xml_compare(expected, found)
218217

219218

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+
220259
def test_service_property(capsys):
221260
""" Check that Script.service returns a valid Service instance as soon
222261
as the stream_events method is called, but not before.

0 commit comments

Comments
 (0)