self._cur_entity = _Entity.EVENT_PAYLOAD
- if ev.payload_type is None:
- raise ConfigError('missing payload type in event "{}"'.format(ev_name), e)
-
try:
self._validate_entity(ev.payload_type)
except Exception as e:
raise ConfigError('invalid payload type in event "{}"'.format(ev_name), e)
- if not ev.payload_type.fields:
- raise ConfigError('empty payload type in event "{}"'.format(ev_name), e)
+ if stream.is_event_empty(ev):
+ raise ConfigError('event "{}" is empty'.format(ev_name))
except Exception as e:
raise ConfigError('invalid stream "{}"'.format(stream_name), e)
raise ConfigError('invalid event context type for event "{}"'.format(ev_name), e)
# validate event payload type
- if ev.payload_type is None:
- raise ConfigError('event payload type must exist in event "{}"'.format(ev_name))
-
- # TODO: also check arrays, sequences, and variants
- if type(ev.payload_type) is metadata.Struct:
- if not ev.payload_type.fields:
- raise ConfigError('event payload type must have at least one field for event "{}"'.format(ev_name))
-
try:
self._validate_entity_type_histology(ev.payload_type)
except Exception as e:
event.context_type = t
- if 'payload-type' not in event_node:
- raise ConfigError('missing "payload-type" property in event object')
-
- if event_node['payload-type'] is not None:
+ if 'payload-type' in event_node and event_node['payload-type'] is not None:
try:
t = self._create_type(event_node['payload-type'])
except Exception as e:
def __getitem__(self, key):
return self.fields[key]
+ def __len__(self):
+ return len(self._fields)
+
class Variant(Type):
def __init__(self):
def events(self):
return self._events
+ def is_event_empty(self, event):
+ total_fields = 0
+
+ if self.event_header_type:
+ total_fields += len(self.event_header_type)
+
+ if self.event_context_type:
+ total_fields += len(self.event_context_type)
+
+ if event.context_type:
+ total_fields += len(event.context_type)
+
+ if event.payload_type:
+ total_fields += len(event.payload_type)
+
+ return total_fields == 0
+
class Metadata:
def __init__(self):
if ev.payload_type is not None:
_gen_entity('fields', ev.payload_type, cg)
+ else:
+ fake_payload = metadata.Struct()
+ fake_payload.min_align = 8
+ _gen_entity('fields', fake_payload, cg)
_gen_end_block(cg)
barectf_config_check_fail
}
-@test 'no "payload-type" property in event object makes barectf fail' {
- barectf_assert_file_exists pt-no.yaml
- barectf_config_check_fail
-}
-
@test 'invalid "payload-type" property field type (not a structure) in event object makes barectf fail' {
barectf_assert_file_exists pt-not-struct.yaml
barectf_config_check_fail
}
-
-@test 'empty struct type as "payload-type" property in event object makes barectf fail' {
- barectf_assert_file_exists pt-empty.yaml
- barectf_config_check_fail
-}