From 0ab20d558bc6d8f1681c0b22f7193cef997677fc Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Tue, 1 Jun 2021 03:33:34 -0400 Subject: [PATCH] island: Add unit test to verify '~' expanded in data_dir --- .../setup/test_island_config_options.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/monkey/tests/unit_tests/monkey_island/setup/test_island_config_options.py b/monkey/tests/unit_tests/monkey_island/setup/test_island_config_options.py index 9175bc274..240def907 100644 --- a/monkey/tests/unit_tests/monkey_island/setup/test_island_config_options.py +++ b/monkey/tests/unit_tests/monkey_island/setup/test_island_config_options.py @@ -1,3 +1,5 @@ +import os + from monkey_island.cc.server_utils.consts import ( DEFAULT_DATA_DIR, DEFAULT_LOG_LEVEL, @@ -37,3 +39,16 @@ def test_island_config_options__mongodb(): assert options.start_mongodb == DEFAULT_START_MONGO_DB options = IslandConfigOptions(TEST_CONFIG_FILE_CONTENTS_NO_STARTMONGO) assert options.start_mongodb == DEFAULT_START_MONGO_DB + + +def set_home_env(monkeypatch, tmpdir): + monkeypatch.setenv("HOME", str(tmpdir)) + + +def test_island_config_options__data_dir_expanduser(monkeypatch, tmpdir): + set_home_env(monkeypatch, tmpdir) + DATA_DIR_NAME = "test_data_dir" + + options = IslandConfigOptions({"data_dir": f"~/{DATA_DIR_NAME}"}) + + assert options.data_dir == os.path.join(tmpdir, DATA_DIR_NAME)