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 1313# limitations under the License.
1414from os import environ
1515from unittest import TestCase
16- from unittest .mock import patch
16+ from unittest .mock import MagicMock , patch
1717
1818from google .auth .transport .requests import AuthorizedSession
1919
2727
2828
2929class TestOTLPTraceAutoInstrumentGcpCredential (TestCase ):
30+ @patch ("google.auth.default" )
3031 @patch .dict (
3132 environ ,
3233 {
3334 _OTEL_PYTHON_EXPORTER_OTLP_HTTP_TRACES_CREDENTIAL_PROVIDER : "gcp_http_credentials" ,
3435 _OTEL_PYTHON_EXPORTER_OTLP_GRPC_TRACES_CREDENTIAL_PROVIDER : "gcp_grpc_credentials" ,
3536 },
3637 )
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
3839 """Test that OTel configuration internals can load the credentials from entrypoint by
3940 name"""
40-
41+ mock_credentials = MagicMock ()
42+ mock_credentials .project_id = "test-project"
43+ mock_default .return_value = (mock_credentials , "test-project" )
4144 http_exporter = OTLPSpanExporter ()
4245 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