Пример #1
0
 def test_calculate_final_values(self):
     fields = {**self.schema_base(), **self.schema_user(), **self.schema_server()}
     finalizer.perform_reuse(fields)
     finalizer.calculate_final_values(fields)
     base_fields = fields['base']['fields']
     server_fields = fields['server']['fields']
     user_fields = fields['user']['fields']
     # Pre-calculated path-based values
     # root=true
     timestamp_details = base_fields['@timestamp']['field_details']
     self.assertEqual(timestamp_details['flat_name'], '@timestamp',
                      "Field sets with root=true must not namespace field names with the field set's name")
     self.assertEqual(timestamp_details['dashed_name'], '-timestamp')
     # root=false
     self.assertEqual(server_fields['ip']['field_details']['flat_name'], 'server.ip',
                      "Field sets with root=false must namespace field names with the field set's name")
     self.assertEqual(server_fields['ip']['field_details']['dashed_name'], 'server-ip')
     # reused
     server_user_name_details = server_fields['user']['fields']['name']['field_details']
     self.assertEqual(server_user_name_details['flat_name'], 'server.user.name')
     self.assertEqual(server_user_name_details['dashed_name'], 'server-user-name')
     # self-nestings
     user_target_name_details = user_fields['target']['fields']['name']['field_details']
     self.assertEqual(user_target_name_details['flat_name'], 'user.target.name')
     self.assertEqual(user_target_name_details['dashed_name'], 'user-target-name')
     # multi-fields flat_name
     user_full_name_details = user_fields['full_name']['field_details']
     self.assertEqual(user_full_name_details['multi_fields'][0]['flat_name'], 'user.full_name.text')
Пример #2
0
 def test_perform_reuse_with_foreign_reuse_and_self_reuse(self):
     fields = {**self.schema_user(), **self.schema_server(), **self.schema_process()}
     # If the test had multiple foreign destinations for user fields, we could compare them together instead
     finalizer.perform_reuse(fields)
     process_fields = fields['process']['fields']
     server_fields = fields['server']['fields']
     user_fields = fields['user']['fields']
     # Expected reuse
     self.assertIn('parent', process_fields)
     self.assertIn('user', server_fields)
     self.assertIn('target', user_fields)
     self.assertIn('effective', user_fields)
     # Sanity check for presence of leaf fields, after performing reuse
     self.assertIn('name', user_fields['target']['fields'])
     self.assertIn('name', user_fields['effective']['fields'])
     self.assertIn('name', server_fields['user']['fields'])
     self.assertIn('pid', process_fields['parent']['fields'])
     # Ensure the parent field of reused fields is marked as intermediate
     self.assertTrue(server_fields['user']['field_details']['intermediate'])
     self.assertTrue(process_fields['parent']['field_details']['intermediate'])
     self.assertTrue(user_fields['target']['field_details']['intermediate'])
     self.assertTrue(user_fields['effective']['field_details']['intermediate'])
     # No unexpected cross-nesting
     self.assertNotIn('target', user_fields['target']['fields'])
     self.assertNotIn('target', user_fields['effective']['fields'])
     self.assertNotIn('target', server_fields['user']['fields'])
     # Legacy list of nestings, added to destination schema
     self.assertIn('process.parent', fields['process']['schema_details']['nestings'])
     self.assertIn('user.effective', fields['user']['schema_details']['nestings'])
     self.assertIn('user.target', fields['user']['schema_details']['nestings'])
     self.assertIn('server.user', fields['server']['schema_details']['nestings'])
     # Attribute 'reused_here' lists nestings inside a destination schema
     self.assertIn({'full': 'process.parent', 'schema_name': 'process', 'short': 'short desc'},
                   fields['process']['schema_details']['reused_here'])
     self.assertIn({'full': 'user.effective', 'schema_name': 'user', 'short': 'short desc'},
                   fields['user']['schema_details']['reused_here'])
     self.assertIn({'full': 'user.target', 'schema_name': 'user', 'short': 'short desc'},
                   fields['user']['schema_details']['reused_here'])
     self.assertIn({'full': 'server.user', 'schema_name': 'user', 'short': 'short desc'},
                   fields['server']['schema_details']['reused_here'])
     # Reused fields have an indication they're reused
     self.assertEqual(process_fields['parent']['field_details']['original_fieldset'], 'process',
                      "The parent field of reused fields should have 'original_fieldset' populated")
     self.assertEqual(process_fields['parent']['fields']['pid']['field_details']['original_fieldset'], 'process',
                      "Leaf fields of reused fields for self-nested fields should have 'original_fieldset'")
     self.assertEqual(server_fields['user']['field_details']['original_fieldset'], 'user',
                      "The parent field of foreign reused fields should have 'original_fieldset' populated")
     self.assertEqual(server_fields['user']['fields']['name']['field_details']['original_fieldset'], 'user')
     # Original fieldset's fields must not be marked with 'original_fieldset='
     self.assertNotIn('original_fieldset', user_fields['name']['field_details'])
     self.assertNotIn('original_fieldset', process_fields['pid']['field_details'])