<filename>tests/test_cli.py
from tempfile import TemporaryDirectory

from click.testing import CliRunner

from meshmon import cli


def reraise(exc_info):
    exc_type, exc_value, exc_traceback = exc_info
    if exc_type is not SystemExit:
        raise exc_type.with_traceback(exc_value, exc_traceback)


def test_run(datastore, database, monkeypatch):
    monkeypatch.setenv("MESHMON_DATASTORE", str(datastore))
    monkeypatch.setenv("MESHMON_DATABASE", database)
    monkeypatch.setenv("MESHMON_INTERVAL_DAYS", "3")
    monkeypatch.setenv("MESHMON_SAMPLE", "0.001")

    runner = CliRunner()
    result = runner.invoke(cli.run)
    reraise(result.exc_info)

    assert result.exit_code == 0
