diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 47b6708..31396e1 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1 @@ -* @leoparente @mfiedorowicz +* @leoparente @ltucker @mfiedorowicz diff --git a/netboxlabs/diode/sdk/ingester.py b/netboxlabs/diode/sdk/ingester.py index ad4c90b..d4d9b7c 100644 --- a/netboxlabs/diode/sdk/ingester.py +++ b/netboxlabs/diode/sdk/ingester.py @@ -710,6 +710,11 @@ def __new__( virtual_machine, VirtualMachinePb, name=virtual_machine ) + if timestamp is None: + ts = _timestamp_pb2.Timestamp() + ts.GetCurrentTime() + timestamp = ts + return EntityPb( site=site, platform=platform, diff --git a/tests/test_ingester.py b/tests/test_ingester.py index e666f50..8d0d510 100644 --- a/tests/test_ingester.py +++ b/tests/test_ingester.py @@ -1,6 +1,7 @@ #!/usr/bin/env python # Copyright 2024 NetBox Labs Inc """NetBox Labs - Tests.""" +from google.protobuf import timestamp_pb2 # ruff: noqa: I001 from netboxlabs.diode.sdk.diode.v1.ingester_pb2 import ( @@ -658,6 +659,38 @@ def test_site_instantiation_with_all_fields(): assert isinstance(tag, TagPb) +def test_entity_instantiation_with_no_timestamp_provided(): + """Check Entity instantiation with no timestamp provided.""" + entity = Entity( + site="Site1", + ) + assert isinstance(entity, EntityPb) + assert isinstance(entity.site, SitePb) + assert entity.site.name == "Site1" + assert entity.timestamp is not None + assert entity.timestamp.seconds > 0 + assert entity.timestamp.nanos > 0 + + +def test_entity_instantiation_with_timestamp_provided(): + """Check Entity instantiation with timestamp provided.""" + current_ts = timestamp_pb2.Timestamp() + current_ts.GetCurrentTime() + + entity = Entity( + site="Site1", + timestamp=current_ts, + ) + assert isinstance(entity, EntityPb) + assert isinstance(entity.site, SitePb) + assert entity.site.name == "Site1" + assert entity.timestamp is not None + assert entity.timestamp.seconds > 0 + assert entity.timestamp.nanos > 0 + assert entity.timestamp.seconds == current_ts.seconds + assert entity.timestamp.nanos == current_ts.nanos + + def test_entity_instantiation_with_site(): """Check Entity instantiation with site.""" entity = Entity(