2017-07-11 04:20:17 +00:00
|
|
|
"""The tests for the Prometheus exporter."""
|
|
|
|
import asyncio
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from homeassistant.setup import async_setup_component
|
|
|
|
import homeassistant.components.prometheus as prometheus
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2018-03-15 20:49:49 +00:00
|
|
|
def prometheus_client(loop, hass, aiohttp_client):
|
2018-05-13 10:09:28 +00:00
|
|
|
"""Initialize an aiohttp_client with Prometheus component."""
|
2017-07-11 04:20:17 +00:00
|
|
|
assert loop.run_until_complete(async_setup_component(
|
|
|
|
hass,
|
|
|
|
prometheus.DOMAIN,
|
2018-06-28 14:49:33 +00:00
|
|
|
{prometheus.DOMAIN: {}},
|
2017-07-11 04:20:17 +00:00
|
|
|
))
|
2018-03-15 20:49:49 +00:00
|
|
|
return loop.run_until_complete(aiohttp_client(hass.http.app))
|
2017-07-11 04:20:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
@asyncio.coroutine
|
|
|
|
def test_view(prometheus_client): # pylint: disable=redefined-outer-name
|
|
|
|
"""Test prometheus metrics view."""
|
|
|
|
resp = yield from prometheus_client.get(prometheus.API_ENDPOINT)
|
|
|
|
|
|
|
|
assert resp.status == 200
|
|
|
|
assert resp.headers['content-type'] == 'text/plain'
|
|
|
|
body = yield from resp.text()
|
|
|
|
body = body.split("\n")
|
|
|
|
|
|
|
|
assert len(body) > 3 # At least two comment lines and a metric
|
|
|
|
for line in body:
|
|
|
|
if line:
|
2017-12-03 22:39:54 +00:00
|
|
|
assert line.startswith('# ') \
|
|
|
|
or line.startswith('process_') \
|
|
|
|
or line.startswith('python_info')
|