|
1 | 1 | #!/usr/bin/env python
|
2 | 2 | # Copyright 2024 NetBox Labs Inc
|
3 | 3 | """NetBox Labs - Tests."""
|
| 4 | +from google.protobuf import timestamp_pb2 |
4 | 5 |
|
5 | 6 | # ruff: noqa: I001
|
6 | 7 | from netboxlabs.diode.sdk.diode.v1.ingester_pb2 import (
|
@@ -658,6 +659,38 @@ def test_site_instantiation_with_all_fields():
|
658 | 659 | assert isinstance(tag, TagPb)
|
659 | 660 |
|
660 | 661 |
|
| 662 | +def test_entity_instantiation_with_no_timestamp_provided(): |
| 663 | + """Check Entity instantiation with no timestamp provided.""" |
| 664 | + entity = Entity( |
| 665 | + site="Site1", |
| 666 | + ) |
| 667 | + assert isinstance(entity, EntityPb) |
| 668 | + assert isinstance(entity.site, SitePb) |
| 669 | + assert entity.site.name == "Site1" |
| 670 | + assert entity.timestamp is not None |
| 671 | + assert entity.timestamp.seconds > 0 |
| 672 | + assert entity.timestamp.nanos > 0 |
| 673 | + |
| 674 | + |
| 675 | +def test_entity_instantiation_with_timestamp_provided(): |
| 676 | + """Check Entity instantiation with timestamp provided.""" |
| 677 | + current_ts = timestamp_pb2.Timestamp() |
| 678 | + current_ts.GetCurrentTime() |
| 679 | + |
| 680 | + entity = Entity( |
| 681 | + site="Site1", |
| 682 | + timestamp=current_ts, |
| 683 | + ) |
| 684 | + assert isinstance(entity, EntityPb) |
| 685 | + assert isinstance(entity.site, SitePb) |
| 686 | + assert entity.site.name == "Site1" |
| 687 | + assert entity.timestamp is not None |
| 688 | + assert entity.timestamp.seconds > 0 |
| 689 | + assert entity.timestamp.nanos > 0 |
| 690 | + assert entity.timestamp.seconds == current_ts.seconds |
| 691 | + assert entity.timestamp.nanos == current_ts.nanos |
| 692 | + |
| 693 | + |
661 | 694 | def test_entity_instantiation_with_site():
|
662 | 695 | """Check Entity instantiation with site."""
|
663 | 696 | entity = Entity(
|
|
0 commit comments