mirror of
https://github.com/thegeeklab/prometheus-pve-sd.git
synced 2024-06-02 07:59:40 +02:00
add missing test
This commit is contained in:
parent
e5d02b3293
commit
fd2d89b14b
35
prometheuspvesd/test/fixtures/fixtures.py
vendored
35
prometheuspvesd/test/fixtures/fixtures.py
vendored
|
@ -3,6 +3,9 @@
|
|||
import environs
|
||||
import pytest
|
||||
|
||||
from prometheuspvesd.model import Host
|
||||
from prometheuspvesd.model import HostList
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def builtins():
|
||||
|
@ -293,3 +296,35 @@ def networks():
|
|||
}
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def inventory():
|
||||
hostlist = HostList()
|
||||
hostlist.add_host(Host("101", "host1", "129.168.0.1", False, "qemu"))
|
||||
hostlist.add_host(Host("202", "host2", "129.168.0.2", False, "qemu"))
|
||||
|
||||
return hostlist
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def labels():
|
||||
return [{
|
||||
"targets": ["host1"],
|
||||
"labels": {
|
||||
"__meta_pve_ipv4": "129.168.0.1",
|
||||
"__meta_pve_ipv6": "False",
|
||||
"__meta_pve_name": "host1",
|
||||
"__meta_pve_type": "qemu",
|
||||
"__meta_pve_vmid": "101"
|
||||
}
|
||||
}, {
|
||||
"targets": ["host2"],
|
||||
"labels": {
|
||||
"__meta_pve_ipv4": "129.168.0.2",
|
||||
"__meta_pve_ipv6": "False",
|
||||
"__meta_pve_name": "host2",
|
||||
"__meta_pve_type": "qemu",
|
||||
"__meta_pve_vmid": "202"
|
||||
}
|
||||
}]
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
"""Test CLI class."""
|
||||
import json
|
||||
|
||||
import pytest
|
||||
from proxmoxer import ProxmoxAPI
|
||||
|
||||
|
@ -66,3 +68,18 @@ def test_cli_api_error(mocker, builtins, capsys):
|
|||
stdout, stderr = capsys.readouterr()
|
||||
assert "Proxmoxer API error: Dummy API Exception" in stderr
|
||||
assert e.value.code == 1
|
||||
|
||||
|
||||
def test_cli_write(mocker, tmp_path, builtins, inventory, labels):
|
||||
temp = tmp_path / "temp.txt"
|
||||
out = tmp_path / "out.txt"
|
||||
|
||||
builtins["output_file"]["default"] = out.as_posix()
|
||||
|
||||
mocker.patch.dict(Config.SETTINGS, builtins)
|
||||
mocker.patch.object(Discovery, "_auth", return_value=mocker.create_autospec(ProxmoxAPI))
|
||||
mocker.patch.object(Discovery, "propagate", return_value=inventory)
|
||||
mocker.patch("tempfile.NamedTemporaryFile", return_value=temp.open("w"))
|
||||
|
||||
PrometheusSD()
|
||||
assert json.loads(out.read_text()) == labels
|
||||
|
|
Loading…
Reference in New Issue
Block a user