def setUp(self): super(EventMonUploaderTest, self).setUp() tmp_handle, self.event_mon_file = tempfile.mkstemp() os.close(tmp_handle) event_mon.close() event_mon.setup_monitoring( run_type='file', hostname='test_host', output_file=self.event_mon_file)
def test_logging_on_appengine(self, environ): environ.get.return_value = 'Google App Engine/1.2.3' event_mon.setup_monitoring() self.assertIsInstance(config._router, router._LoggingStreamRouter) environ.get.return_value = 'Development/1.2' event_mon.setup_monitoring() self.assertIsInstance(config._router, router._LoggingStreamRouter)
def test_logging_on_appengine(self, environ): environ.get.return_value = 'Google App Engine/1.2.3' event_mon.setup_monitoring() self.assertIsInstance(config._router, router._LoggingStreamRouter) environ.get.return_value = 'Development/1.2' event_mon.setup_monitoring() self.assertIsInstance(config._router, router._LoggingStreamRouter)
def test_default_event(self): # The protobuf structure is actually an API not an implementation detail # so it's sane to test for changes. event_mon.setup_monitoring() event = event_mon.get_default_event() self.assertTrue(event.event_source.HasField('host_name')) self.assertFalse(event.event_source.HasField('service_name')) self.assertFalse(event.event_source.HasField('appengine_name'))
def test_default_event(self): # The protobuf structure is actually an API not an implementation detail # so it's sane to test for changes. event_mon.setup_monitoring() event = event_mon.get_default_event() self.assertTrue(event.event_source.HasField('host_name')) self.assertFalse(event.event_source.HasField('service_name')) self.assertFalse(event.event_source.HasField('appengine_name'))
def test_set_default_event(self): event_mon.setup_monitoring() orig_event = event_mon.get_default_event() # Set the new default event to something different from orig_event # to make sure it has changed. event = chrome_infra_log_pb2.ChromeInfraEvent() new_hostname = orig_event.event_source.host_name + '.foo' event.event_source.host_name = new_hostname event_mon.set_default_event(event) new_event = event_mon.get_default_event() self.assertEquals(new_event.event_source.host_name, new_hostname)
def test_set_default_event(self): event_mon.setup_monitoring() orig_event = event_mon.get_default_event() # Set the new default event to something different from orig_event # to make sure it has changed. event = chrome_infra_log_pb2.ChromeInfraEvent() new_hostname = orig_event.event_source.host_name + '.foo' event.event_source.host_name = new_hostname event_mon.set_default_event(event) new_event = event_mon.get_default_event() self.assertEquals(new_event.event_source.host_name, new_hostname)
def test_default_event_with_values(self): # The protobuf structure is actually an API not an implementation detail # so it's sane to test for changes. hostname = 'a' service_name = 'b' appengine_name = 'c' event_mon.setup_monitoring(hostname=hostname, service_name=service_name, appengine_name=appengine_name) event = event_mon.get_default_event() self.assertEquals(event.event_source.host_name, hostname) self.assertEquals(event.event_source.service_name, service_name) self.assertEquals(event.event_source.appengine_name, appengine_name)
def test_default_event_with_values(self): # The protobuf structure is actually an API not an implementation detail # so it's sane to test for changes. hostname = 'a' service_name = 'b' appengine_name = 'c' event_mon.setup_monitoring( hostname=hostname, service_name=service_name, appengine_name=appengine_name ) event = event_mon.get_default_event() self.assertEquals(event.event_source.host_name, hostname) self.assertEquals(event.event_source.service_name, service_name) self.assertEquals(event.event_source.appengine_name, appengine_name)
def setUp(self): # Use the dry run mode instead of a mock. event_mon.setup_monitoring(run_type='dry')
def test_run_type_test(self): event_mon.setup_monitoring(run_type='test') self.assertIsInstance(config._router, router._HttpRouter)
def test_run_type_invalid(self): event_mon.setup_monitoring(run_type='invalid.') self.assertNotIsInstance(config._router, router._HttpRouter)
def test_get_default_event(self): event_mon.setup_monitoring() orig_event = config._cache['default_event'] self.assertEqual(orig_event, event_mon.get_default_event()) self.assertIsNot(orig_event, event_mon.get_default_event())
def test_set_default_event_bad_type(self): event_mon.setup_monitoring() # bad type with self.assertRaises(TypeError): event_mon.set_default_event({'hostname': 'foo'})
def test_run_type_invalid(self): event_mon.setup_monitoring(run_type='invalid.') self.assertFalse(isinstance(config._router, router._HttpRouter))
def test_run_type_test(self): event_mon.setup_monitoring(run_type='test', service_account_creds='creds') self.assertEquals(config._cache['service_account_creds'], 'creds')
def test_get_default_event(self): event_mon.setup_monitoring() orig_event = config._cache['default_event'] self.assertEqual(orig_event, event_mon.get_default_event()) self.assertIsNot(orig_event, event_mon.get_default_event())
def test_set_default_event_bad_type(self): event_mon.setup_monitoring() # bad type with self.assertRaises(TypeError): event_mon.set_default_event({'hostname': 'foo'})
def setUp(self): event_mon.setup_monitoring(run_type='dry')
def setUp(self): # Use the dry run mode instead of a mock. event_mon.setup_monitoring(run_type='dry')