1- from unittest .mock import patch
1+ from unittest .mock import patch , Mock , ANY
22
33from durabletask .internal .shared import (DefaultClientInterceptorImpl ,
44 get_default_host_address ,
@@ -39,3 +39,50 @@ def test_get_grpc_channel_with_metadata():
3939 assert args [0 ] == mock_channel .return_value
4040 assert isinstance (args [1 ], DefaultClientInterceptorImpl )
4141 assert args [1 ]._metadata == METADATA
42+
43+
44+ def test_grpc_channel_with_host_name_protocol_stripping ():
45+ with patch ('grpc.insecure_channel' ) as mock_insecure_channel , patch (
46+ 'grpc.secure_channel' ) as mock_secure_channel :
47+
48+ host_name = "myserver.com:1234"
49+
50+ prefix = "grpc://"
51+ get_grpc_channel (prefix + host_name , METADATA )
52+ mock_insecure_channel .assert_called_with (host_name )
53+
54+ prefix = "http://"
55+ get_grpc_channel (prefix + host_name , METADATA )
56+ mock_insecure_channel .assert_called_with (host_name )
57+
58+ prefix = "HTTP://"
59+ get_grpc_channel (prefix + host_name , METADATA )
60+ mock_insecure_channel .assert_called_with (host_name )
61+
62+ prefix = "GRPC://"
63+ get_grpc_channel (prefix + host_name , METADATA )
64+ mock_insecure_channel .assert_called_with (host_name )
65+
66+ prefix = ""
67+ get_grpc_channel (prefix + host_name , METADATA )
68+ mock_insecure_channel .assert_called_with (host_name )
69+
70+ prefix = "grpcs://"
71+ get_grpc_channel (prefix + host_name , METADATA )
72+ mock_secure_channel .assert_called_with (host_name , ANY )
73+
74+ prefix = "https://"
75+ get_grpc_channel (prefix + host_name , METADATA )
76+ mock_secure_channel .assert_called_with (host_name , ANY )
77+
78+ prefix = "HTTPS://"
79+ get_grpc_channel (prefix + host_name , METADATA )
80+ mock_secure_channel .assert_called_with (host_name , ANY )
81+
82+ prefix = "GRPCS://"
83+ get_grpc_channel (prefix + host_name , METADATA )
84+ mock_secure_channel .assert_called_with (host_name , ANY )
85+
86+ prefix = ""
87+ get_grpc_channel (prefix + host_name , METADATA , True )
88+ mock_secure_channel .assert_called_with (host_name , ANY )
0 commit comments