@@ -168,7 +168,7 @@ TEST_F(OtlpGrpcExporterTestPeer, ConfigFromEnv)
168168 const std::string cacert_str = " --begin and end fake cert--" ;
169169 setenv (" OTEL_EXPORTER_OTLP_CERTIFICATE_STRING" , cacert_str.c_str (), 1 );
170170 setenv (" OTEL_EXPORTER_OTLP_SSL_ENABLE" , " True" , 1 );
171- const std::string endpoint = " http ://localhost:9999" ;
171+ const std::string endpoint = " https ://localhost:9999" ;
172172 setenv (" OTEL_EXPORTER_OTLP_ENDPOINT" , endpoint.c_str (), 1 );
173173 setenv (" OTEL_EXPORTER_OTLP_TIMEOUT" , " 20050ms" , 1 );
174174 setenv (" OTEL_EXPORTER_OTLP_HEADERS" , " k1=v1,k2=v2" , 1 );
@@ -211,6 +211,76 @@ TEST_F(OtlpGrpcExporterTestPeer, ConfigFromEnv)
211211}
212212# endif
213213
214+ # ifndef NO_GETENV
215+ // Test exporter configuration options with use_ssl_credentials
216+ TEST_F (OtlpGrpcExporterTestPeer, ConfigHttpsSecureFromEnv)
217+ {
218+ // https takes precedence over insecure
219+ const std::string endpoint = " https://localhost:9999" ;
220+ setenv (" OTEL_EXPORTER_OTLP_ENDPOINT" , endpoint.c_str (), 1 );
221+ setenv (" OTEL_EXPORTER_OTLP_TRACES_INSECURE" , " true" , 1 );
222+
223+ std::unique_ptr<OtlpGrpcExporter> exporter (new OtlpGrpcExporter ());
224+ EXPECT_EQ (GetOptions (exporter).use_ssl_credentials , true );
225+ EXPECT_EQ (GetOptions (exporter).endpoint , endpoint);
226+
227+ unsetenv (" OTEL_EXPORTER_OTLP_ENDPOINT" );
228+ unsetenv (" OTEL_EXPORTER_OTLP_TRACES_INSECURE" );
229+ }
230+ # endif
231+
232+ # ifndef NO_GETENV
233+ // Test exporter configuration options with use_ssl_credentials
234+ TEST_F (OtlpGrpcExporterTestPeer, ConfigHttpInsecureFromEnv)
235+ {
236+ // http takes precedence over secure
237+ const std::string endpoint = " http://localhost:9999" ;
238+ setenv (" OTEL_EXPORTER_OTLP_ENDPOINT" , endpoint.c_str (), 1 );
239+ setenv (" OTEL_EXPORTER_OTLP_TRACES_INSECURE" , " false" , 1 );
240+
241+ std::unique_ptr<OtlpGrpcExporter> exporter (new OtlpGrpcExporter ());
242+ EXPECT_EQ (GetOptions (exporter).use_ssl_credentials , false );
243+ EXPECT_EQ (GetOptions (exporter).endpoint , endpoint);
244+
245+ unsetenv (" OTEL_EXPORTER_OTLP_ENDPOINT" );
246+ unsetenv (" OTEL_EXPORTER_OTLP_TRACES_INSECURE" );
247+ }
248+ # endif
249+
250+ # ifndef NO_GETENV
251+ // Test exporter configuration options with use_ssl_credentials
252+ TEST_F (OtlpGrpcExporterTestPeer, ConfigUnknownSecureFromEnv)
253+ {
254+ const std::string endpoint = " localhost:9999" ;
255+ setenv (" OTEL_EXPORTER_OTLP_ENDPOINT" , endpoint.c_str (), 1 );
256+ setenv (" OTEL_EXPORTER_OTLP_TRACES_INSECURE" , " false" , 1 );
257+
258+ std::unique_ptr<OtlpGrpcExporter> exporter (new OtlpGrpcExporter ());
259+ EXPECT_EQ (GetOptions (exporter).use_ssl_credentials , true );
260+ EXPECT_EQ (GetOptions (exporter).endpoint , endpoint);
261+
262+ unsetenv (" OTEL_EXPORTER_OTLP_ENDPOINT" );
263+ unsetenv (" OTEL_EXPORTER_OTLP_TRACES_INSECURE" );
264+ }
265+ # endif
266+
267+ # ifndef NO_GETENV
268+ // Test exporter configuration options with use_ssl_credentials
269+ TEST_F (OtlpGrpcExporterTestPeer, ConfigUnknownInsecureFromEnv)
270+ {
271+ const std::string endpoint = " localhost:9999" ;
272+ setenv (" OTEL_EXPORTER_OTLP_ENDPOINT" , endpoint.c_str (), 1 );
273+ setenv (" OTEL_EXPORTER_OTLP_TRACES_INSECURE" , " true" , 1 );
274+
275+ std::unique_ptr<OtlpGrpcExporter> exporter (new OtlpGrpcExporter ());
276+ EXPECT_EQ (GetOptions (exporter).use_ssl_credentials , false );
277+ EXPECT_EQ (GetOptions (exporter).endpoint , endpoint);
278+
279+ unsetenv (" OTEL_EXPORTER_OTLP_ENDPOINT" );
280+ unsetenv (" OTEL_EXPORTER_OTLP_TRACES_INSECURE" );
281+ }
282+ # endif
283+
214284} // namespace otlp
215285} // namespace exporter
216286OPENTELEMETRY_END_NAMESPACE
0 commit comments