From 7e8ef44a24b59649a849eade8f3605806da82f08 Mon Sep 17 00:00:00 2001 From: Michal Polovka Date: Tue, 24 May 2022 09:35:59 +0200 Subject: [PATCH] Tests: User to be warned about incorrect output type Test if the error message for the situation is descriptive and user-friendly when the output_type provided in the cfg file is incorrect. Related: https://bugzilla.redhat.com/show_bug.cgi?id=2079698 Signed-off-by: Michal Polovka --- tests/test_options.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/test_options.py b/tests/test_options.py index f66033c0..e54a0e2b 100644 --- a/tests/test_options.py +++ b/tests/test_options.py @@ -3,8 +3,10 @@ # import argparse +import io import os import tempfile +from contextlib import redirect_stdout from unittest.mock import patch from ipahealthcheck.core.core import RunChecks @@ -70,3 +72,35 @@ def test_cfg_file_debug_option(mock_parse, mock_run, mock_service): assert run.options.debug finally: os.remove(config_path) + + +@patch('ipahealthcheck.core.core.run_service_plugins') +@patch('ipahealthcheck.core.core.run_plugins') +@patch('ipahealthcheck.core.core.parse_options') +def test_incorrect_output_type_cfg_file(mock_parse, mock_run, mock_service): + """ + Test the error message is user-friendly if the incorrect output type is + provided in cfg file + + Related: https://bugzilla.redhat.com/show_bug.cgi?id=2079698 + """ + mock_service.return_value = (Results(), []) + mock_run.return_value = Results() + mock_parse.return_value = options + fd, config_path = tempfile.mkstemp() + os.close(fd) + with open(config_path, "w") as fd: + fd.write('[default]\n') + fd.write('output_type=42\n') + + try: + run = RunChecks([], config_path) + + f = io.StringIO() + with redirect_stdout(f): + run.run_healthcheck() + + assert "Unknown output-type" in f.getvalue() + + finally: + os.remove(config_path)