Add metrics upload by UDP to graphite (#43751)
This commit is contained in:
parent
20485eb132
commit
642bb91a9a
2 changed files with 48 additions and 19 deletions
|
@ -24,7 +24,7 @@ class TestGraphite(unittest.TestCase):
|
|||
def setup_method(self, method):
|
||||
"""Set up things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self.gf = graphite.GraphiteFeeder(self.hass, "foo", 123, "ha")
|
||||
self.gf = graphite.GraphiteFeeder(self.hass, "foo", 123, "tcp", "ha")
|
||||
|
||||
def teardown_method(self, method):
|
||||
"""Stop everything that was started."""
|
||||
|
@ -45,10 +45,23 @@ class TestGraphite(unittest.TestCase):
|
|||
|
||||
assert setup_component(self.hass, graphite.DOMAIN, config)
|
||||
assert mock_gf.call_count == 1
|
||||
assert mock_gf.call_args == mock.call(self.hass, "foo", 123, "me")
|
||||
assert mock_gf.call_args == mock.call(self.hass, "foo", 123, "tcp", "me")
|
||||
assert mock_socket.call_count == 1
|
||||
assert mock_socket.call_args == mock.call(socket.AF_INET, socket.SOCK_STREAM)
|
||||
|
||||
@patch("socket.socket")
|
||||
@patch("homeassistant.components.graphite.GraphiteFeeder")
|
||||
def test_full_udp_config(self, mock_gf, mock_socket):
|
||||
"""Test setup with full configuration and UDP protocol."""
|
||||
config = {
|
||||
"graphite": {"host": "foo", "port": 123, "protocol": "udp", "prefix": "me"}
|
||||
}
|
||||
|
||||
assert setup_component(self.hass, graphite.DOMAIN, config)
|
||||
assert mock_gf.call_count == 1
|
||||
assert mock_gf.call_args == mock.call(self.hass, "foo", 123, "udp", "me")
|
||||
assert mock_socket.call_count == 0
|
||||
|
||||
@patch("socket.socket")
|
||||
@patch("homeassistant.components.graphite.GraphiteFeeder")
|
||||
def test_config_port(self, mock_gf, mock_socket):
|
||||
|
@ -63,7 +76,7 @@ class TestGraphite(unittest.TestCase):
|
|||
def test_subscribe(self):
|
||||
"""Test the subscription."""
|
||||
fake_hass = mock.MagicMock()
|
||||
gf = graphite.GraphiteFeeder(fake_hass, "foo", 123, "ha")
|
||||
gf = graphite.GraphiteFeeder(fake_hass, "foo", 123, "tcp", "ha")
|
||||
fake_hass.bus.listen_once.has_calls(
|
||||
[
|
||||
mock.call(EVENT_HOMEASSISTANT_START, gf.start_listen),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue