@@ -9,7 +9,16 @@ def test_getter_setter():
99 """Test for Endpoint constructor, getters, and setters with fluent interface."""
1010
1111 endpoint = Endpoint (address = None , port = None , domain_name = None )
12-
12+ endpoint .set_port (77777 ) # Currently accepted but invalid
13+
14+ # Test boundary conditions
15+ endpoint .set_port (1 ) # Minimum valid port
16+ endpoint .set_port (65535 ) # Maximum valid port
17+
18+ # Test None values
19+ endpoint .set_port (None )
20+ endpoint .set_address (None )
21+ endpoint .set_domain_name (None )
1322
1423 # Test fluent interface (method chaining)
1524 result = endpoint .set_address (b'127.0.1.1' )
@@ -40,23 +49,38 @@ def test_constructor_with_values():
4049 assert endpoint .get_domain_name () == "example.com"
4150
4251
43- @pytest .mark .parametrize ("input_port, expected_port" , [
44- (0 , 50211 ),
45- (50111 , 50211 ),
46- (80 , 80 )
47- ])
48-
52+ @pytest .mark .parametrize (
53+ ("input_port" , "expected_port" ),
54+ [
55+ (0 , 50211 ),
56+ (50111 , 50211 ),
57+ (80 , 80 ),
58+ ],
59+ )
4960def test_from_proto_port_mapping (input_port , expected_port ):
50-
51- """ Tests the logic that converts a Protobuf ServiceEndpoint into an Endpoint object. """
61+ """Tests port mapping logic when converting Protobuf ServiceEndpoint to Endpoint.
5262
63+ Port mapping rules:
64+ - Port 0 or 50111 maps to 50211 (legacy/default behavior)
65+ - Other ports pass through unchanged
66+ """
67+
5368 mock_proto = MagicMock ()
5469 mock_proto .port = input_port
5570 mock_proto .ipAddressV4 = b"127.0.1.1"
5671 mock_proto .domain_name = "redpanda.com"
57-
72+
5873 endpoint = Endpoint ._from_proto (mock_proto )
74+
75+ # Verify port mapping
5976 assert endpoint .get_port () == expected_port
77+
78+ # Verify all fields are mapped correctly (not just port)
79+ assert endpoint .get_address () == b"127.0.1.1" , "Address must be mapped from proto"
80+ assert endpoint .get_domain_name () == "redpanda.com" , "Domain name must be mapped from proto"
81+
82+ # Protect against breaking changes - PRIORITY 1
83+ assert isinstance (endpoint , Endpoint ), "Must return Endpoint instance"
6084
6185def test_to_proto ():
6286
@@ -87,6 +111,16 @@ def test_str_with_none_values():
87111 with pytest .raises (AttributeError ):
88112 str (endpoint )
89113
114+ @pytest .mark .parametrize ("invalid_data" , [
115+ {"port" : 77777 , "domain_name" : "test.com" },
116+ {"ip_address_v4" : "127.0.0.1" , "domain_name" : "test.com" },
117+ {"ip_address_v4" : "127.0.0.1" , "port" : 77777 },
118+ ])
119+ def test_from_dict_missing_fields (invalid_data ):
120+ """Test that from_dict raises ValueError when required fields are missing."""
121+ with pytest .raises (ValueError , match = "JSON data must contain" ):
122+ Endpoint .from_dict (invalid_data )
123+
90124def test_from_dict_error ():
91125
92126 """Validates 'Guard Clause' error handling"""
0 commit comments