@@ -231,6 +231,46 @@ def test_client_sets_up_insecure_channel_when_grpc_scheme_is_found_in_target():
231
231
mock_insecure_channel .assert_called_once ()
232
232
233
233
234
+ def test_insecure_channel_options_with_primary_user_agent ():
235
+ """Check that DiodeClient.__init__() sets the gRPC primary_user_agent option for insecure channel."""
236
+ with mock .patch ("grpc.insecure_channel" ) as mock_insecure_channel :
237
+ client = DiodeClient (
238
+ target = "grpc://localhost:8081" ,
239
+ app_name = "my-producer" ,
240
+ app_version = "0.0.1" ,
241
+ api_key = "abcde" ,
242
+ )
243
+
244
+ mock_insecure_channel .assert_called_once ()
245
+ _ , kwargs = mock_insecure_channel .call_args
246
+ assert kwargs ["options" ] == (
247
+ (
248
+ "grpc.primary_user_agent" ,
249
+ f"{ client .name } /{ client .version } { client .app_name } /{ client .app_version } " ,
250
+ ),
251
+ )
252
+
253
+
254
+ def test_secure_channel_options_with_primary_user_agent ():
255
+ """Check that DiodeClient.__init__() sets the gRPC primary_user_agent option for secure channel."""
256
+ with mock .patch ("grpc.secure_channel" ) as mock_secure_channel :
257
+ client = DiodeClient (
258
+ target = "grpcs://localhost:8081" ,
259
+ app_name = "my-producer" ,
260
+ app_version = "0.0.1" ,
261
+ api_key = "abcde" ,
262
+ )
263
+
264
+ mock_secure_channel .assert_called_once ()
265
+ _ , kwargs = mock_secure_channel .call_args
266
+ assert kwargs ["options" ] == (
267
+ (
268
+ "grpc.primary_user_agent" ,
269
+ f"{ client .name } /{ client .version } { client .app_name } /{ client .app_version } " ,
270
+ ),
271
+ )
272
+
273
+
234
274
def test_client_interceptor_setup_with_path ():
235
275
"""Check that DiodeClient.__init__() sets up the gRPC interceptor when a path is provided."""
236
276
client = DiodeClient (
0 commit comments