diff options
author | Johnson Shi <Johnson.Shi@microsoft.com> | 2020-10-15 07:19:57 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-15 10:19:57 -0400 |
commit | 3b05b1a6c58dfc7533a16f795405bda0e53aa9d8 (patch) | |
tree | 2f22615203d14a973b2ac8177e61418fdac1e7df /tests/unittests/test_reporting_hyperv.py | |
parent | 8ec8c3fc63a59b85888a0b52356b784314a1d4cc (diff) | |
download | vyos-cloud-init-3b05b1a6c58dfc7533a16f795405bda0e53aa9d8.tar.gz vyos-cloud-init-3b05b1a6c58dfc7533a16f795405bda0e53aa9d8.zip |
azure: clean up and refactor report_diagnostic_event (#563)
This moves logging into `report_diagnostic_event`, to clean up its callsites.
Diffstat (limited to 'tests/unittests/test_reporting_hyperv.py')
-rw-r--r-- | tests/unittests/test_reporting_hyperv.py | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/tests/unittests/test_reporting_hyperv.py b/tests/unittests/test_reporting_hyperv.py index 47ede670..3f63a60e 100644 --- a/tests/unittests/test_reporting_hyperv.py +++ b/tests/unittests/test_reporting_hyperv.py @@ -188,18 +188,34 @@ class TextKvpReporter(CiTestCase): if not re.search("variant=" + pattern, evt_msg): raise AssertionError("missing distro variant string") - def test_report_diagnostic_event(self): + def test_report_diagnostic_event_without_logger_func(self): reporter = HyperVKvpReportingHandler(kvp_file_path=self.tmp_file_path) + diagnostic_msg = "test_diagnostic" + reporter.publish_event( + azure.report_diagnostic_event(diagnostic_msg)) + reporter.q.join() + kvps = list(reporter._iterate_kvps(0)) + self.assertEqual(1, len(kvps)) + evt_msg = kvps[0]['value'] + + if diagnostic_msg not in evt_msg: + raise AssertionError("missing expected diagnostic message") + def test_report_diagnostic_event_with_logger_func(self): + reporter = HyperVKvpReportingHandler(kvp_file_path=self.tmp_file_path) + logger_func = mock.MagicMock() + diagnostic_msg = "test_diagnostic" reporter.publish_event( - azure.report_diagnostic_event("test_diagnostic")) + azure.report_diagnostic_event(diagnostic_msg, + logger_func=logger_func)) reporter.q.join() kvps = list(reporter._iterate_kvps(0)) self.assertEqual(1, len(kvps)) evt_msg = kvps[0]['value'] - if "test_diagnostic" not in evt_msg: + if diagnostic_msg not in evt_msg: raise AssertionError("missing expected diagnostic message") + logger_func.assert_called_once_with(diagnostic_msg) def test_report_compressed_event(self): reporter = HyperVKvpReportingHandler(kvp_file_path=self.tmp_file_path) |