Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.next.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Thanks, you're awesome :-) -->
* Add support for reusing offical fieldsets in custom schemas. #751
* Add full path names to reused fieldsets in `nestings` array in `ecs_nested.yml`. #803
* Allow shorthand notation for including all subfields in subsets. #805
* Prevent custom schema from defining a type more than once. #821

#### Deprecated

Expand Down
1 change: 1 addition & 0 deletions scripts/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pip
PyYAML==5.3b1
autopep8==1.4.4
yamllint==1.19.0
mock
2 changes: 1 addition & 1 deletion scripts/schema_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def load_schema_files(files):
fields_nested = {}
for f in files:
new_fields = read_schema_file(f)
fields_nested.update(new_fields)
fields_nested = ecs_helpers.safe_merge_dicts(fields_nested, new_fields)
return fields_nested


Expand Down
42 changes: 42 additions & 0 deletions scripts/tests/test_schema_reader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import sys
import unittest
import mock

sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

Expand Down Expand Up @@ -71,6 +72,47 @@ def test_load_schemas_with_empty_list_loads_nothing(self):
result = schema_reader.load_schemas([])
self.assertEqual(result, ({}))

@mock.patch('scripts.schema_reader.read_schema_file')
def test_load_schemas_fail_on_redefinition(self, mock_read_schema):
mock_read_schema.side_effect = [
{
'file': {
'name': 'file',
'type': 'keyword'
}
},
{
'file': {
'name': 'file',
'type': 'text'
}
}
]
with self.assertRaises(ValueError):
schema_reader.load_schema_files(['a', 'b'])

@mock.patch('scripts.schema_reader.read_schema_file')
def test_load_schemas_allows_unique_fields(self, mock_read_schema):
file_map = {
'file': {
'name': 'file',
'type': 'keyword'
}
}
host_map = {
'host': {
'name': 'host',
'type': 'text'
}
}
mock_read_schema.side_effect = [file_map, host_map]
exp = {
'file': file_map['file'],
'host': host_map['host']
}
res = schema_reader.load_schema_files(['a', 'b'])
self.assertEqual(res, exp)

def test_flatten_fields(self):
fields = {
'top_level': {
Expand Down