1+ import mock
2+ import pytest
3+
4+ from ddtrace .contrib .grpc .utils import _parse_target_from_args
15from ddtrace .contrib .grpc .utils import parse_method_path
26
37
@@ -11,3 +15,27 @@ def test_parse_method_path_without_package():
1115 method_path = "/service/method"
1216 parsed = parse_method_path (method_path )
1317 assert parsed == (None , "service" , "method" )
18+
19+
20+ @mock .patch ("ddtrace.contrib.grpc.utils.log" )
21+ @pytest .mark .parametrize (
22+ "args, kwargs, result, log_warning_call" ,
23+ [
24+ (("localhost:1234" ,), dict (), ("localhost" , 1234 ), None ),
25+ (("localhost" ,), dict (), ("localhost" , None ), None ),
26+ (("[::]:1234" ,), dict (), ("::" , 1234 ), None ),
27+ (("[::]" ,), dict (), ("::" , None ), None ),
28+ (None , dict (target = "localhost:1234" ), ("localhost" , 1234 ), None ),
29+ (None , dict (target = "localhost" ), ("localhost" , None ), None ),
30+ (None , dict (target = "[::]:1234" ), ("::" , 1234 ), None ),
31+ (None , dict (target = "[::]" ), ("::" , None ), None ),
32+ (("localhost:foo" ,), dict (), ("localhost" , None ), ("Non-integer port in target '%s'" , "localhost:foo" )),
33+ (("" ,), dict (), (None , None ), None ),
34+ ],
35+ )
36+ def test_parse_target_from_args (mock_log , args , kwargs , result , log_warning_call ):
37+ assert _parse_target_from_args (args , kwargs ) == result
38+ if log_warning_call :
39+ mock_log .warning .assert_called_once_with (* log_warning_call )
40+ else :
41+ mock_log .warning .assert_not_called ()
0 commit comments