@@ -49,18 +49,34 @@ def test_create_client_missing_endpoint_raises(self):
4949 with pytest .raises (ValueError , match = "endpoint, deployment_id, and namespace are required" ):
5050 create_client (deployment_id = "dep-1" , namespace = "ns-1" )
5151
52- def test_create_client_missing_endpoint_records_error_metric (self ):
52+ @pytest .mark .parametrize (
53+ ("kwargs" , "match" ),
54+ [
55+ (
56+ {"deployment_id" : "dep-1" , "namespace" : "ns-1" },
57+ "endpoint, deployment_id, and namespace are required" ,
58+ ),
59+ (
60+ {
61+ "endpoint" : "localhost:4317" ,
62+ "deployment_id" : "bad value" ,
63+ "namespace" : "ns-1" ,
64+ },
65+ "deployment_id" ,
66+ ),
67+ ],
68+ )
69+ def test_create_client_config_errors_record_error_metric (self , kwargs , match ):
5370 with patch (
5471 "sap_cloud_sdk.core.auditlog_ng.record_error_metric"
5572 ) as mock_error_metric :
5673 with pytest .raises (
5774 ValueError ,
58- match = "endpoint, deployment_id, and namespace are required" ,
75+ match = match ,
5976 ):
6077 create_client (
61- deployment_id = "dep-1" ,
62- namespace = "ns-1" ,
6378 _telemetry_source = Module .DMS ,
79+ ** kwargs ,
6480 )
6581
6682 mock_error_metric .assert_called_once_with (
@@ -96,13 +112,30 @@ def test_create_client_unexpected_exception_wraps_in_client_creation_error(
96112 ):
97113 mock_provider_cls .side_effect = RuntimeError ("Unexpected failure" )
98114
99- with pytest .raises (ClientCreationError , match = "Failed to create audit log NG client" ):
100- create_client (
101- endpoint = "localhost:4317" ,
102- deployment_id = "dep-1" ,
103- namespace = "ns-1" ,
104- insecure = True ,
115+ with patch (
116+ "sap_cloud_sdk.core.telemetry.metrics_decorator.record_error_metric"
117+ ) as mock_error_metric :
118+ with patch (
119+ "sap_cloud_sdk.core.telemetry.metrics_decorator.record_request_metric"
120+ ) as mock_request_metric :
121+ with pytest .raises (
122+ ClientCreationError , match = "Failed to create audit log NG client"
123+ ):
124+ create_client (
125+ endpoint = "localhost:4317" ,
126+ deployment_id = "dep-1" ,
127+ namespace = "ns-1" ,
128+ insecure = True ,
129+ _telemetry_source = Module .DMS ,
130+ )
131+
132+ mock_error_metric .assert_called_once_with (
133+ Module .AUDITLOG_NG ,
134+ Module .DMS ,
135+ Operation .AUDITLOG_CREATE_CLIENT ,
136+ False ,
105137 )
138+ mock_request_metric .assert_not_called ()
106139
107140 @patch ("sap_cloud_sdk.core.auditlog_ng.client._create_log_exporter" )
108141 @patch ("sap_cloud_sdk.core.auditlog_ng.client.LoggerProvider" )
0 commit comments