def test_get_storage(self): envs = { "TSURU_METRICS_BACKEND": "fake", } os.environ.update(envs) stats = Stats("endpoint", "pubsub", 1.0, "ssh_server") storage = stats.get_storage() self.assertIsInstance(storage, FakeBackend)
def test_get_a_not_registered_backend(self): envs = { "TSURU_METRICS_BACKEND": "doesnotexist", } os.environ.update(envs) stats = Stats("endpoint", "pubsub", 1.0, "ssh_server") storage = stats.get_storage() # when a backend does not exists the default should be returned self.assertIsInstance(storage, StatsdBackend)
def test_connections_established(self, conn_mock): conn = Mock(status="ESTABLISHED") conn_mock.return_value = [conn, conn, conn, conn, conn] stats = Stats("endpoint", "pubsub", 1.0, "ssh_server") established = stats.connections_established() self.assertEqual(5, established) conn_mock.assert_called_with("tcp")
def test_statsd_default_storage(self): del os.environ["TSURU_METRICS_BACKEND"] stats = Stats("endpoint", "pubsub", 1.0, "ssh_server") storage = stats.get_storage() self.assertIsInstance(storage, StatsdBackend)
def test_net_io(self, net_io_mock): stats = Stats("endpoint", "pubsub", 1.0, "ssh_server") stats.net_io() net_io_mock.assert_called_with()
def test_disk_usage(self, disk_usage_mock): stats = Stats("endpoint", "pubsub", 1.0, "ssh_server") stats.disk_usage() disk_usage_mock.assert_called_with("/")