File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed
exporter/exporter-credential-providers/gcp-credential-provider/tests Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change 13
13
# limitations under the License.
14
14
from os import environ
15
15
from unittest import TestCase
16
- from unittest .mock import patch
16
+ from unittest .mock import MagicMock , patch
17
17
18
18
from google .auth .transport .requests import AuthorizedSession
19
19
27
27
28
28
29
29
class TestOTLPTraceAutoInstrumentGcpCredential (TestCase ):
30
+ @patch ("google.auth.default" )
30
31
@patch .dict (
31
32
environ ,
32
33
{
33
34
_OTEL_PYTHON_EXPORTER_OTLP_HTTP_TRACES_CREDENTIAL_PROVIDER : "gcp_http_credentials" ,
34
35
_OTEL_PYTHON_EXPORTER_OTLP_GRPC_TRACES_CREDENTIAL_PROVIDER : "gcp_grpc_credentials" ,
35
36
},
36
37
)
37
- def test_loads_otlp_exporters_with_google_creds (self ): # pylint: disable=no-self-use
38
+ def test_loads_otlp_exporters_with_google_creds (self , mock_default ): # pylint: disable=no-self-use
38
39
"""Test that OTel configuration internals can load the credentials from entrypoint by
39
40
name"""
40
-
41
+ mock_credentials = MagicMock ()
42
+ mock_credentials .project_id = "test-project"
43
+ mock_default .return_value = (mock_credentials , "test-project" )
41
44
http_exporter = OTLPSpanExporter ()
42
45
assert isinstance (http_exporter ._session , AuthorizedSession )
46
+ # Assert that google.auth.default was called
47
+ mock_default .assert_called_once ()
You can’t perform that action at this time.
0 commit comments