|
5 | 5 | import json |
6 | 6 | import logging |
7 | 7 | import os |
8 | | -from typing import Generator |
| 8 | +from typing import Any, Dict, Generator |
9 | 9 | from unittest.mock import Mock |
10 | 10 |
|
11 | 11 | import pytest |
@@ -717,3 +717,36 @@ def test_is_service_or_endpoint_ignored(self) -> None: |
717 | 717 | # don't ignore other services |
718 | 718 | assert not self.agent._HostAgent__is_endpoint_ignored("service3") |
719 | 719 | assert not self.agent._HostAgent__is_endpoint_ignored("service3") |
| 720 | + |
| 721 | + @pytest.mark.parametrize( |
| 722 | + "input_data", |
| 723 | + [ |
| 724 | + { |
| 725 | + "agentUuid": "test-uuid", |
| 726 | + }, |
| 727 | + { |
| 728 | + "pid": 1234, |
| 729 | + }, |
| 730 | + { |
| 731 | + "extraHeaders": ["value-3"], |
| 732 | + }, |
| 733 | + ], |
| 734 | + ids=["missing_pid", "missing_agent_uuid", "missing_both_required_keys"], |
| 735 | + ) |
| 736 | + def test_set_from_missing_required_keys( |
| 737 | + self, input_data: Dict[str, Any], caplog: pytest.LogCaptureFixture |
| 738 | + ) -> None: |
| 739 | + """Test set_from when required keys are missing in res_data.""" |
| 740 | + agent = HostAgent() |
| 741 | + caplog.set_level(logging.DEBUG, logger="instana") |
| 742 | + |
| 743 | + res_data = { |
| 744 | + "secrets": {"matcher": "value-1", "list": ["value-2"]}, |
| 745 | + } |
| 746 | + res_data.update(input_data) |
| 747 | + |
| 748 | + agent.set_from(res_data) |
| 749 | + |
| 750 | + assert agent.announce_data is None |
| 751 | + assert "Missing required keys in announce response" in caplog.messages[-1] |
| 752 | + assert str(res_data) in caplog.messages[-1] |
0 commit comments