Browse Source

added unittest for get_config_dir function

Narendra Vardi 7 năm trước cách đây
mục cha
commit
a3f1e6e250
1 tập tin đã thay đổi với 12 bổ sung1 xóa
  1. 12 1
      src/borg/testsuite/helpers.py

+ 12 - 1
src/borg/testsuite/helpers.py

@@ -18,7 +18,7 @@ from ..helpers import Buffer
 from ..helpers import partial_format, format_file_size, parse_file_size, format_timedelta, format_line, PlaceholderError, replace_placeholders
 from ..helpers import make_path_safe, clean_lines
 from ..helpers import interval, prune_within, prune_split
-from ..helpers import get_cache_dir, get_keys_dir, get_security_dir
+from ..helpers import get_cache_dir, get_keys_dir, get_security_dir, get_config_dir
 from ..helpers import is_slow_msgpack
 from ..helpers import yes, TRUISH, FALSISH, DEFAULTISH
 from ..helpers import StableDict, int_to_bigint, bigint_to_int, bin_to_hex
@@ -447,6 +447,17 @@ class TestParseTimestamp(BaseTestCase):
         self.assert_equal(parse_timestamp('2015-04-19T20:25:00'), datetime(2015, 4, 19, 20, 25, 0, 0, timezone.utc))
 
 
+def test_get_config_dir(monkeypatch):
+    """test that get_config_dir respects environment"""
+    monkeypatch.delenv('BORG_CONFIG_DIR', raising=False)
+    monkeypatch.delenv('XDG_CONFIG_HOME', raising=False)
+    assert get_config_dir() == os.path.join(os.path.expanduser('~'), '.config', 'borg')
+    monkeypatch.setenv('XDG_CONFIG_HOME', '/var/tmp/.config')
+    assert get_config_dir() == os.path.join('/var/tmp/.config', 'borg')
+    monkeypatch.setenv('BORG_CONFIG_DIR', '/var/tmp')
+    assert get_config_dir() == '/var/tmp'
+
+
 def test_get_cache_dir(monkeypatch):
     """test that get_cache_dir respects environment"""
     monkeypatch.delenv('BORG_CACHE_DIR', raising=False)