diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
commit | 19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch) | |
tree | 42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/jaegertracing/opentracing-cpp/test/dynamic_load_test.cpp | |
parent | Initial commit. (diff) | |
download | ceph-upstream.tar.xz ceph-upstream.zip |
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/jaegertracing/opentracing-cpp/test/dynamic_load_test.cpp | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/src/jaegertracing/opentracing-cpp/test/dynamic_load_test.cpp b/src/jaegertracing/opentracing-cpp/test/dynamic_load_test.cpp new file mode 100644 index 000000000..8ad76e384 --- /dev/null +++ b/src/jaegertracing/opentracing-cpp/test/dynamic_load_test.cpp @@ -0,0 +1,90 @@ +#include <opentracing/dynamic_load.h> +#include <cstdio> +#include <fstream> +#include <iterator> +#include <random> +using namespace opentracing; + +#define CATCH_CONFIG_RUNNER +#include <opentracing/catch2/catch.hpp> + +static std::string mocktracer_library; + +TEST_CASE("dynamic_load") { + std::string error_message; + + SECTION( + "Dynamically loading a library that doesn't exists gives a proper error " + "code.") { + auto handle_maybe = DynamicallyLoadTracingLibrary("abc/123", error_message); + REQUIRE(!handle_maybe); + CHECK(handle_maybe.error() == dynamic_load_failure_error); + } + + error_message.clear(); + auto handle_maybe = + DynamicallyLoadTracingLibrary(mocktracer_library.c_str(), error_message); + REQUIRE(handle_maybe); + REQUIRE(error_message.empty()); + + SECTION("Creating a tracer from invalid json gives an error.") { + auto tracer_maybe = + handle_maybe->tracer_factory().MakeTracer("abc 123", error_message); + REQUIRE(!tracer_maybe); + } + + SECTION("Creating a tracer with an invalid output_file gives an error.") { + auto tracer_maybe = handle_maybe->tracer_factory().MakeTracer( + R"({"output_file": ""})", error_message); + REQUIRE(!tracer_maybe); + REQUIRE(tracer_maybe.error() == invalid_configuration_error); + } + + SECTION( + "We can create spans from an OpenTracing library dynamically loaded.") { + std::string span_filename{"spans."}; + const auto random_id = std::random_device{}(); + span_filename.append(std::to_string(random_id)); + std::string configuration = R"({ "output_file": ")"; + configuration.append(span_filename); + configuration.append(R"(" })"); + + { + auto tracer_maybe = handle_maybe->tracer_factory().MakeTracer( + configuration.c_str(), error_message); + REQUIRE(tracer_maybe); + auto tracer = *tracer_maybe; + tracer->StartSpan("abc"); + tracer->Close(); + } + + std::ifstream istream{span_filename}; + REQUIRE(istream.good()); + std::string spans_json{std::istreambuf_iterator<char>{istream}, + std::istreambuf_iterator<char>{}}; + istream.close(); + std::remove(span_filename.c_str()); + CHECK(!spans_json.empty()); + } +} + +int main(int argc, char* argv[]) { + Catch::Session session; + + using namespace Catch::clara; + auto cli = session.cli() | Opt(mocktracer_library, + "mocktracer_library")["--mocktracer_library"]; + + session.cli(cli); + int rcode = session.applyCommandLine(argc, argv); + if (rcode != 0) { + return rcode; + } + + if (mocktracer_library.empty()) { + std::cerr << "Must provide mocktracer_library!\n"; + return -1; + } + + return session.run(); +} |