Skip to content

Commit 1a589b1

Browse files
authored
Fixing windows unit tests (#1234)
1 parent 7090587 commit 1a589b1

File tree

2 files changed

+32
-29
lines changed

2 files changed

+32
-29
lines changed

tests/unit/builtin_monitors/windows_event_log_monitor_tests/cache_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525

2626
@skipIf(sys.version_info < (3, 0, 0), "Skipping under Python 2")
27-
@skipIf(sys.platform != "Windows", "Skipping on non-Windows platforms")
27+
@skipIf(sys.platform != "win32", "Skipping on non-Windows platforms")
2828
class CacheTest(BaseScalyrLogCaptureTestCase):
2929
def test_fixed_size(self):
3030
cache = Cache(3, 3600)

tests/unit/builtin_monitors/windows_event_log_monitor_tests/windows_event_log_monitor_test.py

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
import pytest
2020
import sys
2121
import tempfile
22+
from scalyr_agent.builtin_monitors.windows_event_log_monitor import NewJsonApi
2223

23-
if sys.platform == "Windows":
24+
if sys.platform == "win32":
2425
import scalyr_agent.builtin_monitors.windows_event_log_monitor
2526
from scalyr_agent.builtin_monitors.windows_event_log_monitor import (
2627
WindowEventLogMonitor,
@@ -37,15 +38,15 @@
3738
def _get_parameter_msg_fixture_path():
3839
# TODO Document how the test dll is created
3940
return os.path.join(
40-
os.path.dirname(os.path.dirname(__file__)),
41+
os.path.dirname(os.path.dirname(os.path.dirname(__file__))),
4142
"fixtures",
4243
"parametermsgfixture.dll",
4344
)
4445

4546

4647
@pytest.mark.windows_platform
4748
class WindowsEventLogMonitorTest(ScalyrTestCase):
48-
@skipIf(sys.platform != "Windows", "Skipping tests under non-Windows platform")
49+
@skipIf(sys.platform != "win32", "Skipping tests under non-Windows platform")
4950
def test_emit_warning_on_maximum_records_per_source_config_option_new_api(self):
5051
monitor_config = {
5152
"module": "windows_event_log_monitor",
@@ -105,7 +106,7 @@ def test_emit_warning_on_maximum_records_per_source_config_option_new_api(self):
105106
"affect when using new evt API."
106107
)
107108

108-
@skipIf(sys.platform != "Windows", "Skipping tests under non-Windows platform")
109+
@skipIf(sys.platform != "win32", "Skipping tests under non-Windows platform")
109110
def test_newjsonapi_backwards_compatible(self):
110111
monitor_config = {
111112
"module": "windows_event_log_monitor",
@@ -133,7 +134,7 @@ def test_newjsonapi_backwards_compatible(self):
133134
)
134135
)
135136

136-
@skipIf(sys.platform != "Windows", "Skipping tests under non-Windows platform")
137+
@skipIf(sys.platform != "win32", "Skipping tests under non-Windows platform")
137138
def test_convert_json_array_to_object(self):
138139
self.assertEqual(
139140
scalyr_agent.builtin_monitors.windows_event_log_monitor._convert_json_array_to_object(
@@ -195,7 +196,7 @@ def test_convert_json_array_to_object(self):
195196
{"n": {"a": 1}, "n2": {"b": 2}, "2": {"c": 3, "@Name": "n"}},
196197
)
197198

198-
@skipIf(sys.platform != "Windows", "Skipping tests under non-Windows platform")
199+
@skipIf(sys.platform != "win32", "Skipping tests under non-Windows platform")
199200
def test_strip_xmltodict_prefixes(self):
200201
self.assertEqual(
201202
scalyr_agent.builtin_monitors.windows_event_log_monitor._strip_xmltodict_prefixes(
@@ -239,23 +240,24 @@ def test_strip_xmltodict_prefixes(self):
239240
[{"a": "a", "Text": "t"}],
240241
)
241242

242-
@skipIf(sys.platform != "Windows", "Skipping tests under non-Windows platform")
243+
@skipIf(sys.platform != "win32", "Skipping tests under non-Windows platform")
243244
@mock.patch(
244245
"scalyr_agent.builtin_monitors.windows_event_log_monitor._DLL.dllpath",
245246
return_value=_get_parameter_msg_fixture_path(),
246247
)
247248
def test_replace_param_placeholders(self, *args):
248249
# pylint: disable=no-member
249-
monitor_config = {
250-
"module": "windows_event_log_monitor",
251-
"sources": "Application, Security, System",
252-
"event_types": "All",
253-
"json": True,
250+
json_api_config = {
251+
"dll_handle_cache_size": 100,
252+
"dll_handle_cache_ttl": 100,
253+
"placeholder_param_cache_size": 100,
254+
"placeholder_param_cache_ttl": 100,
255+
"placeholder_render": True
254256
}
255257
scalyr_agent.builtin_monitors.windows_event_log_monitor.windll = mock.Mock()
256258
mock_logger = mock.Mock()
257259

258-
monitor = WindowEventLogMonitor(monitor_config, mock_logger)
260+
json_api = NewJsonApi(json_api_config, mock_logger, None)
259261
test_events = [
260262
{
261263
"Event": {
@@ -283,43 +285,44 @@ def test_replace_param_placeholders(self, *args):
283285
},
284286
]
285287

286-
result = monitor._replace_param_placeholders(test_events[0])
288+
result = json_api._replace_param_placeholders(test_events[0])
287289
self.assertEqual(result["Event"]["EventData"]["Data"], "blarg")
288290

289-
result = monitor._replace_param_placeholders(test_events[1])
291+
result = json_api._replace_param_placeholders(test_events[1])
290292
self.assertEqual(result["Event"]["EventData"]["Data"]["One"], "honk")
291293
self.assertEqual(result["Event"]["EventData"]["Data"]["Two"]["Text"], "rawr")
292294
self.assertEqual(result["Event"]["EventData"]["Data"]["Three"]["Text"], "Nice")
293295

294-
@skipIf(sys.platform != "Windows", "Skipping tests under non-Windows platform")
296+
@skipIf(sys.platform != "win32", "Skipping tests under non-Windows platform")
295297
@mock.patch(
296298
"scalyr_agent.builtin_monitors.windows_event_log_monitor._DLL.dllpath",
297299
return_value=_get_parameter_msg_fixture_path(),
298300
)
299301
def test_param_placeholder_value_resolution(self, *args):
300302
# pylint: disable=no-member
301-
monitor_config = {
302-
"module": "windows_event_log_monitor",
303-
"sources": "Application, Security, System",
304-
"event_types": "All",
305-
"json": True,
303+
json_api_config = {
304+
"dll_handle_cache_size": 100,
305+
"dll_handle_cache_ttl": 100,
306+
"placeholder_param_cache_size": 100,
307+
"placeholder_param_cache_ttl": 100,
308+
"placeholder_render": True
306309
}
307310
scalyr_agent.builtin_monitors.windows_event_log_monitor.windll = mock.Mock()
308311
mock_logger = mock.Mock()
309312

310-
monitor = WindowEventLogMonitor(monitor_config, mock_logger)
311-
value = monitor._param_placeholder_value("MyChannel", "MyProvider", "%%392")
313+
json_api = NewJsonApi(json_api_config, mock_logger, None)
314+
value = json_api._param_placeholder_value("MyChannel", "MyProvider", "%%392")
312315
self.assertEqual(value, "blarg")
313-
value = monitor._param_placeholder_value("MyChannel", "MyProvider", "%%553")
316+
value = json_api._param_placeholder_value("MyChannel", "MyProvider", "%%553")
314317
self.assertEqual(value, "honk")
315-
value = monitor._param_placeholder_value("MyChannel", "MyProvider", "%%990")
318+
value = json_api._param_placeholder_value("MyChannel", "MyProvider", "%%990")
316319
self.assertEqual(value, "rawr")
317-
value = monitor._param_placeholder_value("MyChannel", "MyProvider", "%%69")
320+
value = json_api._param_placeholder_value("MyChannel", "MyProvider", "%%69")
318321
self.assertEqual(value, "Nice")
319-
value = monitor._param_placeholder_value("MyChannel", "MyProvider", "%%1111")
322+
value = json_api._param_placeholder_value("MyChannel", "MyProvider", "%%1111")
320323
self.assertEqual(value, "all your base are belong to us")
321324

322-
@skipIf(sys.platform != "Windows", "Skipping tests under non-Windows platform")
325+
@skipIf(sys.platform != "win32", "Skipping tests under non-Windows platform")
323326
def test_parameter_msg_file_location_lookup(self):
324327
msgDLL = _get_parameter_msg_fixture_path()
325328
channel = "Application"

0 commit comments

Comments
 (0)