diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d679c3ec48..30b3b3fbde 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -639,27 +639,6 @@ jobs: - name: run tests run: ./ci/do_ci.sh bazel.macos.test - bazel_notest: - name: Bazel without test - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - submodules: 'recursive' - - name: Mount Bazel Cache - uses: actions/cache@v3 - env: - cache-name: bazel_cache - with: - path: /home/runner/.cache/bazel - key: bazel_test - - name: setup - run: | - sudo ./ci/setup_ci_environment.sh - sudo ./ci/install_bazelisk.sh - - name: run tests - run: ./ci/do_ci.sh bazel.notest - benchmark: name: Benchmark runs-on: ubuntu-latest diff --git a/CMakeLists.txt b/CMakeLists.txt index b72e58a963..de5e714916 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -579,7 +579,6 @@ list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}") include(CTest) if(BUILD_TESTING) - add_definitions(-DENABLE_TEST) if(EXISTS ${CMAKE_BINARY_DIR}/lib/libgtest.a) # Prefer GTest from build tree. GTest is not always working with # CMAKE_PREFIX_PATH diff --git a/ci/do_ci.ps1 b/ci/do_ci.ps1 index b97617e96f..0b6cd9513e 100644 --- a/ci/do_ci.ps1 +++ b/ci/do_ci.ps1 @@ -27,7 +27,7 @@ $VCPKG_DIR = Join-Path "$SRC_DIR" "tools" "vcpkg" switch ($action) { "bazel.build" { - bazel build --copt=-DENABLE_TEST $BAZEL_OPTIONS --action_env=VCPKG_DIR=$VCPKG_DIR --deleted_packages=opentracing-shim -- //... + bazel build $BAZEL_OPTIONS --action_env=VCPKG_DIR=$VCPKG_DIR --deleted_packages=opentracing-shim -- //... $exit = $LASTEXITCODE if ($exit -ne 0) { exit $exit diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 3f85e9c540..f679c6af04 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -69,7 +69,7 @@ fi echo "make command: ${MAKE_COMMAND}" echo "IWYU option: ${IWYU}" -BAZEL_OPTIONS_DEFAULT="--copt=-DENABLE_TEST --copt=-DENABLE_METRICS_EXEMPLAR_PREVIEW" +BAZEL_OPTIONS_DEFAULT="--copt=-DENABLE_METRICS_EXEMPLAR_PREVIEW" BAZEL_OPTIONS="--cxxopt=-std=c++14 $BAZEL_OPTIONS_DEFAULT" BAZEL_TEST_OPTIONS="$BAZEL_OPTIONS --test_output=errors" @@ -434,9 +434,6 @@ elif [[ "$1" == "bazel.macos.test" ]]; then bazel $BAZEL_STARTUP_OPTIONS build $BAZEL_MACOS_OPTIONS -- //... bazel $BAZEL_STARTUP_OPTIONS test $BAZEL_MACOS_TEST_OPTIONS -- //... exit 0 -elif [[ "$1" == "bazel.notest" ]]; then - bazel $BAZEL_STARTUP_OPTIONS build ${BAZEL_OPTIONS_ASYNC/--copt=-DENABLE_TEST /} //... - exit 0 elif [[ "$1" == "bazel.legacy.test" ]]; then # we uses C++ future and async() function to test the Prometheus Exporter functionality, # that make this test always fail. ignore Prometheus exporter here. diff --git a/exporters/otlp/test/otlp_http_exporter_test.cc b/exporters/otlp/test/otlp_http_exporter_test.cc index 76d1e5f8ae..91fc154ec7 100644 --- a/exporters/otlp/test/otlp_http_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_exporter_test.cc @@ -19,6 +19,7 @@ # include "opentelemetry/sdk/trace/batch_span_processor.h" # include "opentelemetry/sdk/trace/batch_span_processor_options.h" # include "opentelemetry/sdk/trace/tracer_provider.h" +# include "opentelemetry/test_common/ext/http/client/http_client_factory.h" # include "opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h" # include "opentelemetry/trace/provider.h" @@ -35,8 +36,6 @@ using opentelemetry::sdk::common::unsetenv; # endif using namespace testing; -# ifdef ENABLE_TEST - OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter { @@ -63,19 +62,19 @@ OtlpHttpClientOptions MakeOtlpHttpClientOptions(HttpRequestContentType content_t std::make_pair("Custom-Header-Key", "Custom-Header-Value")); OtlpHttpClientOptions otlp_http_client_options( options.url, -# ifdef ENABLE_OTLP_HTTP_SSL_PREVIEW +# ifdef ENABLE_OTLP_HTTP_SSL_PREVIEW false, /* ssl_insecure_skip_verify */ "", /* ssl_ca_cert_path */ "", /* ssl_ca_cert_string */ "", /* ssl_client_key_path */ "", /* ssl_client_key_string */ "", /* ssl_client_cert_path */ "", /* ssl_client_cert_string */ -# endif /* ENABLE_OTLP_HTTP_SSL_PREVIEW */ -# ifdef ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW - "", /* ssl_min_tls */ - "", /* ssl_max_tls */ - "", /* ssl_cipher */ - "", /* ssl_cipher_suite */ -# endif /* ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW */ +# endif /* ENABLE_OTLP_HTTP_SSL_PREVIEW */ +# ifdef ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW + "", /* ssl_min_tls */ + "", /* ssl_max_tls */ + "", /* ssl_cipher */ + "", /* ssl_cipher_suite */ +# endif /* ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW */ options.content_type, options.json_bytes_mapping, options.use_json_name, options.console_debug, options.timeout, options.http_headers); if (!async_mode) @@ -104,7 +103,7 @@ class OtlpHttpExporterTestPeer : public ::testing::Test static std::pair> GetMockOtlpHttpClient(HttpRequestContentType content_type, bool async_mode = false) { - auto http_client = http_client::HttpClientFactory::CreateNoSend(); + auto http_client = http_client::HttpClientTestFactory::Create(); return {new OtlpHttpClient(MakeOtlpHttpClientOptions(content_type, async_mode), http_client), http_client}; } @@ -199,7 +198,7 @@ class OtlpHttpExporterTestPeer : public ::testing::Test static_cast(provider.get())->ForceFlush(); } -# ifdef ENABLE_ASYNC_EXPORT +# ifdef ENABLE_ASYNC_EXPORT void ExportJsonIntegrationTestAsync() { auto mock_otlp_client = @@ -293,7 +292,7 @@ class OtlpHttpExporterTestPeer : public ::testing::Test static_cast(provider.get())->ForceFlush(); } -# endif +# endif void ExportBinaryIntegrationTest() { @@ -375,7 +374,7 @@ class OtlpHttpExporterTestPeer : public ::testing::Test static_cast(provider.get())->ForceFlush(); } -# ifdef ENABLE_ASYNC_EXPORT +# ifdef ENABLE_ASYNC_EXPORT void ExportBinaryIntegrationTestAsync() { auto mock_otlp_client = @@ -460,7 +459,7 @@ class OtlpHttpExporterTestPeer : public ::testing::Test static_cast(provider.get())->ForceFlush(); } -# endif +# endif }; TEST(OtlpHttpExporterTest, Shutdown) @@ -480,13 +479,13 @@ TEST_F(OtlpHttpExporterTestPeer, ExportJsonIntegrationTestSync) ExportJsonIntegrationTest(); } -# ifdef ENABLE_ASYNC_EXPORT +# ifdef ENABLE_ASYNC_EXPORT TEST_F(OtlpHttpExporterTestPeer, ExportJsonIntegrationTestAsync) { ExportJsonIntegrationTestAsync(); google::protobuf::ShutdownProtobufLibrary(); } -# endif +# endif // Create spans, let processor call Export() TEST_F(OtlpHttpExporterTestPeer, ExportBinaryIntegrationTestSync) @@ -494,12 +493,12 @@ TEST_F(OtlpHttpExporterTestPeer, ExportBinaryIntegrationTestSync) ExportBinaryIntegrationTest(); } -# ifdef ENABLE_ASYNC_EXPORT +# ifdef ENABLE_ASYNC_EXPORT TEST_F(OtlpHttpExporterTestPeer, ExportBinaryIntegrationTestAsync) { ExportBinaryIntegrationTestAsync(); } -# endif +# endif // Test exporter configuration options TEST_F(OtlpHttpExporterTestPeer, ConfigTest) @@ -528,7 +527,7 @@ TEST_F(OtlpHttpExporterTestPeer, ConfigJsonBytesMappingTest) EXPECT_EQ(GetOptions(exporter).json_bytes_mapping, JsonBytesMappingKind::kHex); } -# ifndef NO_GETENV +# ifndef NO_GETENV // Test exporter configuration options with use_ssl_credentials TEST_F(OtlpHttpExporterTestPeer, ConfigFromEnv) { @@ -609,10 +608,9 @@ TEST_F(OtlpHttpExporterTestPeer, ConfigFromTracesEnv) unsetenv("OTEL_EXPORTER_OTLP_HEADERS"); unsetenv("OTEL_EXPORTER_OTLP_TRACES_HEADERS"); } -# endif +# endif } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE -# endif #endif /* OPENTELEMETRY_STL_VERSION */ diff --git a/exporters/otlp/test/otlp_http_log_record_exporter_test.cc b/exporters/otlp/test/otlp_http_log_record_exporter_test.cc index 13d4fb056f..2e333ff25d 100644 --- a/exporters/otlp/test/otlp_http_log_record_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_log_record_exporter_test.cc @@ -22,6 +22,7 @@ # include "opentelemetry/sdk/logs/exporter.h" # include "opentelemetry/sdk/logs/logger_provider.h" # include "opentelemetry/sdk/resource/resource.h" +# include "opentelemetry/test_common/ext/http/client/http_client_factory.h" # include "opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h" # include @@ -38,8 +39,6 @@ using opentelemetry::sdk::common::unsetenv; using namespace testing; -# ifdef ENABLE_TEST - OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter { @@ -62,19 +61,19 @@ OtlpHttpClientOptions MakeOtlpHttpClientOptions(HttpRequestContentType content_t std::make_pair("Custom-Header-Key", "Custom-Header-Value")); OtlpHttpClientOptions otlp_http_client_options( options.url, -# ifdef ENABLE_OTLP_HTTP_SSL_PREVIEW +# ifdef ENABLE_OTLP_HTTP_SSL_PREVIEW false, /* ssl_insecure_skip_verify */ "", /* ssl_ca_cert_path */ "", /* ssl_ca_cert_string */ "", /* ssl_client_key_path */ "", /* ssl_client_key_string */ "", /* ssl_client_cert_path */ "", /* ssl_client_cert_string */ -# endif /* ENABLE_OTLP_HTTP_SSL_PREVIEW */ -# ifdef ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW - "", /* ssl_min_tls */ - "", /* ssl_max_tls */ - "", /* ssl_cipher */ - "", /* ssl_cipher_suite */ -# endif /* ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW */ +# endif /* ENABLE_OTLP_HTTP_SSL_PREVIEW */ +# ifdef ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW + "", /* ssl_min_tls */ + "", /* ssl_max_tls */ + "", /* ssl_cipher */ + "", /* ssl_cipher_suite */ +# endif /* ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW */ options.content_type, options.json_bytes_mapping, options.use_json_name, options.console_debug, options.timeout, options.http_headers); if (!async_mode) @@ -105,7 +104,7 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test static std::pair> GetMockOtlpHttpClient(HttpRequestContentType content_type, bool async_mode = false) { - auto http_client = http_client::HttpClientFactory::CreateNoSend(); + auto http_client = http_client::HttpClientTestFactory::Create(); return {new OtlpHttpClient(MakeOtlpHttpClientOptions(content_type, async_mode), http_client), http_client}; } @@ -223,7 +222,7 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test provider->ForceFlush(); } -# ifdef ENABLE_ASYNC_EXPORT +# ifdef ENABLE_ASYNC_EXPORT void ExportJsonIntegrationTestAsync() { auto mock_otlp_client = OtlpHttpLogRecordExporterTestPeer::GetMockOtlpHttpClient( @@ -350,7 +349,7 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test provider->ForceFlush(); } -# endif +# endif void ExportBinaryIntegrationTest() { @@ -463,7 +462,7 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test provider->ForceFlush(); } -# ifdef ENABLE_ASYNC_EXPORT +# ifdef ENABLE_ASYNC_EXPORT void ExportBinaryIntegrationTestAsync() { auto mock_otlp_client = OtlpHttpLogRecordExporterTestPeer::GetMockOtlpHttpClient( @@ -579,7 +578,7 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test provider->ForceFlush(); } -# endif +# endif }; TEST(OtlpHttpLogRecordExporterTest, Shutdown) @@ -600,13 +599,13 @@ TEST_F(OtlpHttpLogRecordExporterTestPeer, ExportJsonIntegrationTestSync) ExportJsonIntegrationTest(); } -# ifdef ENABLE_ASYNC_EXPORT +# ifdef ENABLE_ASYNC_EXPORT TEST_F(OtlpHttpLogRecordExporterTestPeer, ExportJsonIntegrationTestAsync) { ExportJsonIntegrationTestAsync(); google::protobuf::ShutdownProtobufLibrary(); } -# endif +# endif // Create log records, let processor call Export() TEST_F(OtlpHttpLogRecordExporterTestPeer, ExportBinaryIntegrationTestSync) @@ -614,12 +613,12 @@ TEST_F(OtlpHttpLogRecordExporterTestPeer, ExportBinaryIntegrationTestSync) ExportBinaryIntegrationTest(); } -# ifdef ENABLE_ASYNC_EXPORT +# ifdef ENABLE_ASYNC_EXPORT TEST_F(OtlpHttpLogRecordExporterTestPeer, ExportBinaryIntegrationTestAsync) { ExportBinaryIntegrationTestAsync(); } -# endif +# endif // Test exporter configuration options TEST_F(OtlpHttpLogRecordExporterTestPeer, ConfigTest) @@ -648,7 +647,7 @@ TEST_F(OtlpHttpLogRecordExporterTestPeer, ConfigJsonBytesMappingTest) EXPECT_EQ(GetOptions(exporter).json_bytes_mapping, JsonBytesMappingKind::kHex); } -# ifndef NO_GETENV +# ifndef NO_GETENV // Test exporter configuration options with use_ssl_credentials TEST_F(OtlpHttpLogRecordExporterTestPeer, ConfigFromEnv) { @@ -737,10 +736,9 @@ TEST_F(OtlpHttpLogRecordExporterTestPeer, DefaultEndpoint) EXPECT_EQ("http://localhost:4317", GetOtlpDefaultGrpcEndpoint()); } -# endif +# endif } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE -# endif #endif /* OPENTELEMETRY_STL_VERSION */ diff --git a/exporters/otlp/test/otlp_http_metric_exporter_test.cc b/exporters/otlp/test/otlp_http_metric_exporter_test.cc index 4b1f7ca164..89162cfd17 100644 --- a/exporters/otlp/test/otlp_http_metric_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_metric_exporter_test.cc @@ -24,6 +24,7 @@ #include "opentelemetry/sdk/metrics/export/metric_producer.h" #include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/test_common/ext/http/client/http_client_factory.h" #include "opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h" #include @@ -40,7 +41,6 @@ using opentelemetry::sdk::common::unsetenv; using namespace testing; -#ifdef ENABLE_TEST OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter { @@ -68,19 +68,19 @@ OtlpHttpClientOptions MakeOtlpHttpClientOptions(HttpRequestContentType content_t std::make_pair("Custom-Header-Key", "Custom-Header-Value")); OtlpHttpClientOptions otlp_http_client_options( options.url, -# ifdef ENABLE_OTLP_HTTP_SSL_PREVIEW +#ifdef ENABLE_OTLP_HTTP_SSL_PREVIEW false, /* ssl_insecure_skip_verify */ "", /* ssl_ca_cert_path */ "", /* ssl_ca_cert_string */ "", /* ssl_client_key_path */ "", /* ssl_client_key_string */ "", /* ssl_client_cert_path */ "", /* ssl_client_cert_string */ -# endif /* ENABLE_OTLP_HTTP_SSL_PREVIEW */ -# ifdef ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW +#endif /* ENABLE_OTLP_HTTP_SSL_PREVIEW */ +#ifdef ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW "", /* ssl_min_tls */ "", /* ssl_max_tls */ "", /* ssl_cipher */ "", /* ssl_cipher_suite */ -# endif /* ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW */ +#endif /* ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW */ options.content_type, options.json_bytes_mapping, options.use_json_name, options.console_debug, options.timeout, options.http_headers); if (!async_mode) @@ -110,23 +110,23 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test static std::pair> GetMockOtlpHttpClient(HttpRequestContentType content_type, bool async_mode = false) { - auto http_client = http_client::HttpClientFactory::CreateNoSend(); + auto http_client = http_client::HttpClientTestFactory::Create(); return {new OtlpHttpClient(MakeOtlpHttpClientOptions(content_type, async_mode), http_client), http_client}; } void ExportJsonIntegrationTestExportSumPointData( -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT bool async_mode -# endif +#endif ) { auto mock_otlp_client = OtlpHttpMetricExporterTestPeer::GetMockOtlpHttpClient(HttpRequestContentType::kJson -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT , async_mode -# endif +#endif ); auto mock_otlp_http_client = mock_otlp_client.first; auto client = mock_otlp_client.second; @@ -197,17 +197,17 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test } void ExportBinaryIntegrationTestExportSumPointData( -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT bool async_mode -# endif +#endif ) { auto mock_otlp_client = OtlpHttpMetricExporterTestPeer::GetMockOtlpHttpClient(HttpRequestContentType::kBinary -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT , async_mode -# endif +#endif ); auto mock_otlp_http_client = mock_otlp_client.first; auto client = mock_otlp_client.second; @@ -292,17 +292,17 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test } void ExportJsonIntegrationTestExportLastValuePointData( -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT bool async_mode -# endif +#endif ) { auto mock_otlp_client = OtlpHttpMetricExporterTestPeer::GetMockOtlpHttpClient(HttpRequestContentType::kJson -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT , async_mode -# endif +#endif ); auto mock_otlp_http_client = mock_otlp_client.first; auto client = mock_otlp_client.second; @@ -378,17 +378,17 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test } void ExportBinaryIntegrationTestExportLastValuePointData( -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT bool async_mode -# endif +#endif ) { auto mock_otlp_client = OtlpHttpMetricExporterTestPeer::GetMockOtlpHttpClient(HttpRequestContentType::kBinary -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT , async_mode -# endif +#endif ); auto mock_otlp_http_client = mock_otlp_client.first; auto client = mock_otlp_client.second; @@ -482,17 +482,17 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test } void ExportJsonIntegrationTestExportHistogramPointData( -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT bool async_mode -# endif +#endif ) { auto mock_otlp_client = OtlpHttpMetricExporterTestPeer::GetMockOtlpHttpClient(HttpRequestContentType::kJson -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT , async_mode -# endif +#endif ); auto mock_otlp_http_client = mock_otlp_client.first; auto client = mock_otlp_client.second; @@ -608,17 +608,17 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test } void ExportBinaryIntegrationTestExportHistogramPointData( -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT bool async_mode -# endif +#endif ) { auto mock_otlp_client = OtlpHttpMetricExporterTestPeer::GetMockOtlpHttpClient(HttpRequestContentType::kBinary -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT , async_mode -# endif +#endif ); auto mock_otlp_http_client = mock_otlp_client.first; auto client = mock_otlp_client.second; @@ -758,7 +758,7 @@ TEST(OtlpHttpMetricExporterTest, Shutdown) EXPECT_EQ(result, opentelemetry::sdk::common::ExportResult::kFailure); } -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT TEST_F(OtlpHttpMetricExporterTestPeer, ExportJsonIntegrationTestSumPointDataAsync) { ExportJsonIntegrationTestExportSumPointData(true); @@ -810,7 +810,7 @@ TEST_F(OtlpHttpMetricExporterTestPeer, ExportBinaryIntegrationTestHistogramPoint ExportBinaryIntegrationTestExportHistogramPointData(false); } -# else +#else TEST_F(OtlpHttpMetricExporterTestPeer, ExportJsonIntegrationTestSumPointData) { ExportJsonIntegrationTestExportSumPointData(); @@ -837,7 +837,7 @@ TEST_F(OtlpHttpMetricExporterTestPeer, ExportBinaryIntegrationTestHistogramPoint { ExportBinaryIntegrationTestExportHistogramPointData(); } -# endif +#endif // Test exporter configuration options TEST_F(OtlpHttpMetricExporterTestPeer, ConfigTest) @@ -867,7 +867,7 @@ TEST_F(OtlpHttpMetricExporterTestPeer, ConfigJsonBytesMappingTest) google::protobuf::ShutdownProtobufLibrary(); } -# ifndef NO_GETENV +#ifndef NO_GETENV // Test exporter configuration options with use_ssl_credentials TEST_F(OtlpHttpMetricExporterTestPeer, ConfigFromEnv) { @@ -976,7 +976,7 @@ TEST_F(OtlpHttpMetricExporterTestPeer, CheckDefaultTemporality) exporter->GetAggregationTemporality( opentelemetry::sdk::metrics::InstrumentType::kObservableUpDownCounter)); } -# endif +#endif // Test Preferred aggregtion temporality selection TEST_F(OtlpHttpMetricExporterTestPeer, PreferredAggergationTemporality) @@ -1053,4 +1053,3 @@ TEST_F(OtlpHttpMetricExporterTestPeer, PreferredAggergationTemporality) } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/ext/include/opentelemetry/ext/http/client/curl/http_client_curl.h b/ext/include/opentelemetry/ext/http/client/curl/http_client_curl.h index ca9a4218ac..45ee13d55c 100644 --- a/ext/include/opentelemetry/ext/http/client/curl/http_client_curl.h +++ b/ext/include/opentelemetry/ext/http/client/curl/http_client_curl.h @@ -191,9 +191,7 @@ class Session : public opentelemetry::ext::http::client::Session, */ const std::string &GetBaseUri() const { return host_; } -#ifdef ENABLE_TEST std::shared_ptr GetRequest() { return http_request_; } -#endif inline HttpClient &GetHttpClient() noexcept { return http_client_; } inline const HttpClient &GetHttpClient() const noexcept { return http_client_; } diff --git a/ext/include/opentelemetry/ext/http/client/http_client_factory.h b/ext/include/opentelemetry/ext/http/client/http_client_factory.h index 8df1e578d2..43e15cf255 100644 --- a/ext/include/opentelemetry/ext/http/client/http_client_factory.h +++ b/ext/include/opentelemetry/ext/http/client/http_client_factory.h @@ -17,10 +17,6 @@ class HttpClientFactory static std::shared_ptr CreateSync(); static std::shared_ptr Create(); - -#ifdef ENABLE_TEST - static std::shared_ptr CreateNoSend(); -#endif }; } // namespace client } // namespace http diff --git a/test_common/include/opentelemetry/test_common/ext/http/client/http_client_test_factory.h b/test_common/include/opentelemetry/test_common/ext/http/client/http_client_test_factory.h new file mode 100644 index 0000000000..51f9502bb8 --- /dev/null +++ b/test_common/include/opentelemetry/test_common/ext/http/client/http_client_test_factory.h @@ -0,0 +1,22 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once +#include "opentelemetry/ext/http/client/http_client.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace ext +{ +namespace http +{ +namespace client +{ +class HttpClientTestFactory +{ +public: + static std::shared_ptr Create(); +}; +} // namespace client +} // namespace http +} // namespace ext +OPENTELEMETRY_END_NAMESPACE diff --git a/test_common/include/opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h b/test_common/include/opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h index 7a6fadbd11..7dddde13d4 100644 --- a/test_common/include/opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h +++ b/test_common/include/opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h @@ -3,17 +3,16 @@ #pragma once -#ifdef ENABLE_TEST -# include "opentelemetry/ext/http/client/http_client.h" -# include "opentelemetry/ext/http/common/url_parser.h" -# include "opentelemetry/version.h" +#include "opentelemetry/ext/http/client/http_client.h" +#include "opentelemetry/ext/http/common/url_parser.h" +#include "opentelemetry/version.h" -# include -# include -# include +#include +#include +#include -# include -# include "gmock/gmock.h" +#include +#include "gmock/gmock.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace ext @@ -37,12 +36,12 @@ class Request : public opentelemetry::ext::http::client::Request method_ = method; } -# ifdef ENABLE_HTTP_SSL_PREVIEW +#ifdef ENABLE_HTTP_SSL_PREVIEW void SetSslOptions(const HttpSslOptions &ssl_options) noexcept override { ssl_options_ = ssl_options; } -# endif /* ENABLE_HTTP_SSL_PREVIEW */ +#endif /* ENABLE_HTTP_SSL_PREVIEW */ void SetBody(opentelemetry::ext::http::client::Body &body) noexcept override { @@ -66,9 +65,9 @@ class Request : public opentelemetry::ext::http::client::Request public: opentelemetry::ext::http::client::Method method_; -# ifdef ENABLE_HTTP_SSL_PREVIEW +#ifdef ENABLE_HTTP_SSL_PREVIEW opentelemetry::ext::http::client::HttpSslOptions ssl_options_; -# endif /* ENABLE_HTTP_SSL_PREVIEW */ +#endif /* ENABLE_HTTP_SSL_PREVIEW */ opentelemetry::ext::http::client::Body body_; opentelemetry::ext::http::client::Headers headers_; std::string uri_; @@ -186,4 +185,3 @@ class HttpClient : public opentelemetry::ext::http::client::HttpClient } // namespace http } // namespace ext OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/test_common/src/http/client/nosend/BUILD b/test_common/src/http/client/nosend/BUILD index 7aaf2a61b5..fa7ba623ab 100644 --- a/test_common/src/http/client/nosend/BUILD +++ b/test_common/src/http/client/nosend/BUILD @@ -6,8 +6,8 @@ package(default_visibility = ["//visibility:public"]) cc_library( name = "http_client_nosend", srcs = [ - "http_client_factory_nosend.cc", "http_client_nosend.cc", + "http_client_test_factory.cc", ], include_prefix = "src/http/client/nosend", tags = [ diff --git a/test_common/src/http/client/nosend/CMakeLists.txt b/test_common/src/http/client/nosend/CMakeLists.txt index 1f32861b41..92a2c1f98c 100644 --- a/test_common/src/http/client/nosend/CMakeLists.txt +++ b/test_common/src/http/client/nosend/CMakeLists.txt @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 if(${BUILD_TESTING}) - add_library(opentelemetry_http_client_nosend http_client_factory_nosend.cc + add_library(opentelemetry_http_client_nosend http_client_test_factory.cc http_client_nosend.cc) set_target_properties(opentelemetry_http_client_nosend diff --git a/test_common/src/http/client/nosend/http_client_nosend.cc b/test_common/src/http/client/nosend/http_client_nosend.cc index dd14e4404a..98cae0476a 100644 --- a/test_common/src/http/client/nosend/http_client_nosend.cc +++ b/test_common/src/http/client/nosend/http_client_nosend.cc @@ -1,8 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_TEST -# include "opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h" +#include "opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace ext @@ -96,4 +95,3 @@ void HttpClient::CleanupSession(uint64_t /* session_id */) {} } // namespace http } // namespace ext OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/test_common/src/http/client/nosend/http_client_factory_nosend.cc b/test_common/src/http/client/nosend/http_client_test_factory.cc similarity index 51% rename from test_common/src/http/client/nosend/http_client_factory_nosend.cc rename to test_common/src/http/client/nosend/http_client_test_factory.cc index c70d1b9578..b39cb285e7 100644 --- a/test_common/src/http/client/nosend/http_client_factory_nosend.cc +++ b/test_common/src/http/client/nosend/http_client_test_factory.cc @@ -1,15 +1,13 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_TEST -# include "opentelemetry/ext/http/client/http_client.h" -# include "opentelemetry/ext/http/client/http_client_factory.h" -# include "opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h" +#include "opentelemetry/ext/http/client/http_client.h" +#include "opentelemetry/test_common/ext/http/client/http_client_factory.h" +#include "opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h" namespace http_client = opentelemetry::ext::http::client; -std::shared_ptr http_client::HttpClientFactory::CreateNoSend() +std::shared_ptr http_client::HttpClientTestFactory::Create() { return std::make_shared(); } -#endif