|
@@ -1,39 +1,39 @@
|
|
import pytest
|
|
import pytest
|
|
|
|
|
|
-from borgmatic.config import override as module
|
|
|
|
|
|
+from borgmatic.config import environment as module
|
|
|
|
|
|
|
|
|
|
def test_env(monkeypatch):
|
|
def test_env(monkeypatch):
|
|
- monkeypatch.setenv("MY_CUSTOM_VALUE", "foo")
|
|
|
|
|
|
+ monkeypatch.setenv('MY_CUSTOM_VALUE', 'foo')
|
|
config = {'key': 'Hello $MY_CUSTOM_VALUE'}
|
|
config = {'key': 'Hello $MY_CUSTOM_VALUE'}
|
|
module.resolve_env_variables(config)
|
|
module.resolve_env_variables(config)
|
|
assert config == {'key': 'Hello $MY_CUSTOM_VALUE'}
|
|
assert config == {'key': 'Hello $MY_CUSTOM_VALUE'}
|
|
|
|
|
|
|
|
|
|
def test_env_braces(monkeypatch):
|
|
def test_env_braces(monkeypatch):
|
|
- monkeypatch.setenv("MY_CUSTOM_VALUE", "foo")
|
|
|
|
|
|
+ monkeypatch.setenv('MY_CUSTOM_VALUE', 'foo')
|
|
config = {'key': 'Hello ${MY_CUSTOM_VALUE}'}
|
|
config = {'key': 'Hello ${MY_CUSTOM_VALUE}'}
|
|
module.resolve_env_variables(config)
|
|
module.resolve_env_variables(config)
|
|
assert config == {'key': 'Hello foo'}
|
|
assert config == {'key': 'Hello foo'}
|
|
|
|
|
|
|
|
|
|
def test_env_default_value(monkeypatch):
|
|
def test_env_default_value(monkeypatch):
|
|
- monkeypatch.delenv("MY_CUSTOM_VALUE", raising=False)
|
|
|
|
|
|
+ monkeypatch.delenv('MY_CUSTOM_VALUE', raising=False)
|
|
config = {'key': 'Hello ${MY_CUSTOM_VALUE:-bar}'}
|
|
config = {'key': 'Hello ${MY_CUSTOM_VALUE:-bar}'}
|
|
module.resolve_env_variables(config)
|
|
module.resolve_env_variables(config)
|
|
assert config == {'key': 'Hello bar'}
|
|
assert config == {'key': 'Hello bar'}
|
|
|
|
|
|
|
|
|
|
def test_env_unknown(monkeypatch):
|
|
def test_env_unknown(monkeypatch):
|
|
- monkeypatch.delenv("MY_CUSTOM_VALUE", raising=False)
|
|
|
|
|
|
+ monkeypatch.delenv('MY_CUSTOM_VALUE', raising=False)
|
|
config = {'key': 'Hello ${MY_CUSTOM_VALUE}'}
|
|
config = {'key': 'Hello ${MY_CUSTOM_VALUE}'}
|
|
with pytest.raises(ValueError):
|
|
with pytest.raises(ValueError):
|
|
module.resolve_env_variables(config)
|
|
module.resolve_env_variables(config)
|
|
|
|
|
|
|
|
|
|
def test_env_full(monkeypatch):
|
|
def test_env_full(monkeypatch):
|
|
- monkeypatch.setenv("MY_CUSTOM_VALUE", "foo")
|
|
|
|
- monkeypatch.delenv("MY_CUSTOM_VALUE2", raising=False)
|
|
|
|
|
|
+ monkeypatch.setenv('MY_CUSTOM_VALUE', 'foo')
|
|
|
|
+ monkeypatch.delenv('MY_CUSTOM_VALUE2', raising=False)
|
|
config = {
|
|
config = {
|
|
'key': 'Hello $MY_CUSTOM_VALUE is not resolved',
|
|
'key': 'Hello $MY_CUSTOM_VALUE is not resolved',
|
|
'dict': {
|
|
'dict': {
|
|
@@ -62,8 +62,8 @@ def test_env_full(monkeypatch):
|
|
'anotherdict': {
|
|
'anotherdict': {
|
|
'key': 'My foo here',
|
|
'key': 'My foo here',
|
|
'other': 'foo',
|
|
'other': 'foo',
|
|
- 'list': ['/home/foo/.local', '/var/log/', '/home/bar/.config',],
|
|
|
|
|
|
+ 'list': ['/home/foo/.local', '/var/log/', '/home/bar/.config'],
|
|
},
|
|
},
|
|
},
|
|
},
|
|
- 'list': ['/home/foo/.local', '/var/log/', '/home/bar/.config',],
|
|
|
|
|
|
+ 'list': ['/home/foo/.local', '/var/log/', '/home/bar/.config'],
|
|
}
|
|
}
|