mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-12 23:15:06 +00:00
Reformat everything.
This commit is contained in:
parent
3f2213791a
commit
340ff8586d
1008 changed files with 61301 additions and 58309 deletions
|
|
@ -14,50 +14,62 @@ import json
|
|||
|
||||
|
||||
class TestSplunkClient(unittest.TestCase):
|
||||
@patch('ansible_collections.community.general.plugins.callback.splunk.socket')
|
||||
@patch("ansible_collections.community.general.plugins.callback.splunk.socket")
|
||||
def setUp(self, mock_socket):
|
||||
mock_socket.gethostname.return_value = 'my-host'
|
||||
mock_socket.gethostbyname.return_value = '1.2.3.4'
|
||||
mock_socket.gethostname.return_value = "my-host"
|
||||
mock_socket.gethostbyname.return_value = "1.2.3.4"
|
||||
self.splunk = SplunkHTTPCollectorSource()
|
||||
self.mock_task = Mock('MockTask')
|
||||
self.mock_task._role = 'myrole'
|
||||
self.mock_task._uuid = 'myuuid'
|
||||
self.task_fields = {'args': {}}
|
||||
self.mock_host = Mock('MockHost')
|
||||
self.mock_host.name = 'myhost'
|
||||
self.mock_task = Mock("MockTask")
|
||||
self.mock_task._role = "myrole"
|
||||
self.mock_task._uuid = "myuuid"
|
||||
self.task_fields = {"args": {}}
|
||||
self.mock_host = Mock("MockHost")
|
||||
self.mock_host.name = "myhost"
|
||||
|
||||
@patch('ansible_collections.community.general.plugins.callback.splunk.now')
|
||||
@patch('ansible_collections.community.general.plugins.callback.splunk.open_url')
|
||||
@patch("ansible_collections.community.general.plugins.callback.splunk.now")
|
||||
@patch("ansible_collections.community.general.plugins.callback.splunk.open_url")
|
||||
def test_timestamp_with_milliseconds(self, open_url_mock, mock_now):
|
||||
mock_now.return_value = datetime(2020, 12, 1)
|
||||
result = TaskResult(host=self.mock_host, task=self.mock_task, return_data={}, task_fields=self.task_fields)
|
||||
|
||||
self.splunk.send_event(
|
||||
url='endpoint', authtoken='token', validate_certs=False, include_milliseconds=True,
|
||||
batch="abcefghi-1234-5678-9012-abcdefghijkl", state='OK', result=result, runtime=100
|
||||
url="endpoint",
|
||||
authtoken="token",
|
||||
validate_certs=False,
|
||||
include_milliseconds=True,
|
||||
batch="abcefghi-1234-5678-9012-abcdefghijkl",
|
||||
state="OK",
|
||||
result=result,
|
||||
runtime=100,
|
||||
)
|
||||
|
||||
args, kwargs = open_url_mock.call_args
|
||||
sent_data = json.loads(args[1])
|
||||
|
||||
self.assertEqual(sent_data['event']['timestamp'], '2020-12-01 00:00:00.000000 +0000')
|
||||
self.assertEqual(sent_data['event']['host'], 'my-host')
|
||||
self.assertEqual(sent_data['event']['ip_address'], '1.2.3.4')
|
||||
self.assertEqual(sent_data["event"]["timestamp"], "2020-12-01 00:00:00.000000 +0000")
|
||||
self.assertEqual(sent_data["event"]["host"], "my-host")
|
||||
self.assertEqual(sent_data["event"]["ip_address"], "1.2.3.4")
|
||||
|
||||
@patch('ansible_collections.community.general.plugins.callback.splunk.now')
|
||||
@patch('ansible_collections.community.general.plugins.callback.splunk.open_url')
|
||||
@patch("ansible_collections.community.general.plugins.callback.splunk.now")
|
||||
@patch("ansible_collections.community.general.plugins.callback.splunk.open_url")
|
||||
def test_timestamp_without_milliseconds(self, open_url_mock, mock_now):
|
||||
mock_now.return_value = datetime(2020, 12, 1)
|
||||
result = TaskResult(host=self.mock_host, task=self.mock_task, return_data={}, task_fields=self.task_fields)
|
||||
|
||||
self.splunk.send_event(
|
||||
url='endpoint', authtoken='token', validate_certs=False, include_milliseconds=False,
|
||||
batch="abcefghi-1234-5678-9012-abcdefghijkl", state='OK', result=result, runtime=100
|
||||
url="endpoint",
|
||||
authtoken="token",
|
||||
validate_certs=False,
|
||||
include_milliseconds=False,
|
||||
batch="abcefghi-1234-5678-9012-abcdefghijkl",
|
||||
state="OK",
|
||||
result=result,
|
||||
runtime=100,
|
||||
)
|
||||
|
||||
args, kwargs = open_url_mock.call_args
|
||||
sent_data = json.loads(args[1])
|
||||
|
||||
self.assertEqual(sent_data['event']['timestamp'], '2020-12-01 00:00:00 +0000')
|
||||
self.assertEqual(sent_data['event']['host'], 'my-host')
|
||||
self.assertEqual(sent_data['event']['ip_address'], '1.2.3.4')
|
||||
self.assertEqual(sent_data["event"]["timestamp"], "2020-12-01 00:00:00 +0000")
|
||||
self.assertEqual(sent_data["event"]["host"], "my-host")
|
||||
self.assertEqual(sent_data["event"]["ip_address"], "1.2.3.4")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue