2022-03-06 22:18:55 +00:00
|
|
|
"""Test Config class."""
|
2024-03-07 10:50:43 +00:00
|
|
|
|
2022-03-06 22:18:55 +00:00
|
|
|
import pytest
|
|
|
|
import ruamel.yaml
|
|
|
|
|
|
|
|
import prometheuspvesd.exception
|
|
|
|
from prometheuspvesd.config import Config
|
|
|
|
|
|
|
|
pytest_plugins = [
|
|
|
|
"prometheuspvesd.test.fixtures.fixtures",
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
def test_yaml_config(mocker, defaults):
|
|
|
|
mocker.patch(
|
|
|
|
"prometheuspvesd.config.default_config_file", "./prometheuspvesd/test/data/config.yml"
|
|
|
|
)
|
|
|
|
config = Config()
|
|
|
|
|
|
|
|
defaults["pve"]["user"] = "root"
|
|
|
|
defaults["pve"]["password"] = "secure"
|
|
|
|
defaults["pve"]["server"] = "proxmox.example.com"
|
2023-09-19 07:00:30 +00:00
|
|
|
defaults["pve"]["token_name"] = "pve_sd"
|
|
|
|
defaults["pve"]["token_value"] = "01234567-89ab-cdef-0123-456789abcdef"
|
2022-03-06 22:18:55 +00:00
|
|
|
|
|
|
|
assert config.config == defaults
|
|
|
|
|
|
|
|
|
2024-01-24 11:50:39 +00:00
|
|
|
def test_yaml_config_error(mocker):
|
2022-03-06 22:18:55 +00:00
|
|
|
mocker.patch(
|
|
|
|
"prometheuspvesd.config.default_config_file", "./prometheuspvesd/test/data/config.yml"
|
|
|
|
)
|
|
|
|
mocker.patch.object(ruamel.yaml.YAML, "load", side_effect=ruamel.yaml.composer.ComposerError)
|
|
|
|
|
|
|
|
with pytest.raises(prometheuspvesd.exception.ConfigError) as e:
|
|
|
|
Config()
|
|
|
|
|
|
|
|
assert "Unable to read config file ./prometheuspvesd/test/data/config.yml" in str(e.value)
|