diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:44:33 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:44:33 +0000 |
commit | b196c6498d22e47bb9d0da0153068ec54eac7956 (patch) | |
tree | 1a994a492581e93224a7ee6455f5d4e9d2ec8e59 /test/tracer_test.cpp | |
parent | Initial commit. (diff) | |
download | opentracing-cpp-81899029a20d74b243d54a8cee68b4cc4071afba.tar.xz opentracing-cpp-81899029a20d74b243d54a8cee68b4cc4071afba.zip |
Adding upstream version 1.6.0.upstream/1.6.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | test/tracer_test.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/tracer_test.cpp b/test/tracer_test.cpp new file mode 100644 index 0000000..eca3a36 --- /dev/null +++ b/test/tracer_test.cpp @@ -0,0 +1,43 @@ +#include <opentracing/ext/tags.h> +#include <opentracing/noop.h> +#include <opentracing/tracer.h> +using namespace opentracing; + +#define CATCH_CONFIG_MAIN +#include <opentracing/catch2/catch.hpp> + +TEST_CASE("tracer") { + auto tracer = MakeNoopTracer(); + + auto span1 = tracer->StartSpan("a"); + CHECK(span1); + + SECTION("Spans provide references to the tracer that created them.") { + CHECK(&span1->tracer() == tracer.get()); + } + + SECTION("Ensure basic operations compile.") { + auto span2 = tracer->StartSpan("b", {ChildOf(&span1->context())}); + CHECK(span2); + span2->SetOperationName("b1"); + span2->SetTag("x", true); + span2->SetTag(opentracing::ext::span_kind, + opentracing::ext::span_kind_rpc_client); + CHECK(span2->BaggageItem("y").empty()); + span2->Log({{"event", "xyz"}, {"abc", 123}}); + span2->Finish(); + } + + SECTION("A reference to a null SpanContext is ignored.") { + StartSpanOptions options; + ChildOf(nullptr).Apply(options); + CHECK(options.references.size() == 0); + } +} + +TEST_CASE("A tracer can be globally registered") { + CHECK(!Tracer::IsGlobalTracerRegistered()); + auto tracer = MakeNoopTracer(); + CHECK(Tracer::InitGlobal(tracer) != nullptr); + CHECK(Tracer::IsGlobalTracerRegistered()); +} |