From 7072e891d55c10ceb3e847145bc4c2b7922df0f3 Mon Sep 17 00:00:00 2001 From: Bernhard Kaindl Date: Tue, 5 Dec 2023 11:00:00 +0100 Subject: [PATCH] tests/unit/test_dir_list.py Test dir_list(cap, path_list) Signed-off-by: Bernhard Kaindl --- tests/unit/test_dir_list.py | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 tests/unit/test_dir_list.py diff --git a/tests/unit/test_dir_list.py b/tests/unit/test_dir_list.py new file mode 100644 index 00000000..8a92e9bb --- /dev/null +++ b/tests/unit/test_dir_list.py @@ -0,0 +1,43 @@ +"""tests/unit/test_dir_list.py: Unit-Test bugtool.dir_list(cap, path_list)""" +import sys +import pytest + + +@pytest.mark.skipif(sys.version_info >= (3, 0), reason="dir_list() is not yet py3") +def test_dir_list(bugtool): + """Test the bugtool function dir_list(cap, path_list) to perform as expected""" + + # Arguments for the positive test: + cap = bugtool.CAP_XENSERVER_CONFIG + path_list = [__file__.replace(".", "*")] + + # Assert that mis-matching cap causes no output in bugtool.data: + bugtool.entries = [bugtool.CAP_DISK_INFO, cap, bugtool.CAP_PAM] + bugtool.dir_list(cap=bugtool.CAP_XENSERVER_LOGS, path_list=path_list) + assert bugtool.data == {} + + # Assert that mis-matching path_list results in no bugtool.data: + bugtool.dir_list(cap=cap, path_list=[__file__ + "*notexist*"]) + assert bugtool.data == {} + + # Assert that matching cap and file pattern causes an entry by glob of path_list to be added: + bugtool.dir_list(cap=cap, path_list=path_list) # matching cap and path_list + + # This assert shows that dir_list() needs an update for Python3: + if sys.version_info.major > 2: + assert bugtool.data == {} + return + + expected_data = { + "ls -l " + + __file__: { + "filter": None, + "cap": "xenserver-config", + "cmd_args": [ + "ls", + "-l", + __file__, + ], + } + } + assert bugtool.data == expected_data