Skip to content

Commit

Permalink
Increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Tax committed Jul 9, 2020
1 parent 0e25607 commit 2597ec8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
2 changes: 2 additions & 0 deletions api/test/trace/noop_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ TEST(NoopTest, UseNoopTracers)

std::vector<std::pair<std::string, std::vector<int>>> attributes3;
s1->AddEvent("abc", attributes3);

s1->SetAttribute("abc", 4);
}
24 changes: 20 additions & 4 deletions sdk/test/trace/tracer_test.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "opentelemetry/sdk/trace/tracer.h"
#include "opentelemetry/sdk/trace/simple_processor.h"
#include "opentelemetry/sdk/trace/samplers/always_on.h"
#include "opentelemetry/sdk/trace/samplers/always_off.h"
#include "opentelemetry/sdk/trace/samplers/always_on.h"
#include "opentelemetry/sdk/trace/simple_processor.h"
#include "opentelemetry/sdk/trace/span_data.h"

#include <gtest/gtest.h>
Expand Down Expand Up @@ -142,7 +142,6 @@ TEST(Tracer, StartSpanWithAttributes)
ASSERT_EQ(3.0, nostd::get<double>(span_data2->GetAttributes().at("attr3")));
}


TEST(Tracer, GetSampler)
{
// Create a Tracer with a default AlwaysOnSampler
Expand All @@ -154,8 +153,25 @@ TEST(Tracer, GetSampler)

// Create a Tracer with a AlwaysOffSampler
std::shared_ptr<SpanProcessor> processor_2(new SimpleSpanProcessor(nullptr));
std::shared_ptr<Tracer> tracer_off(new Tracer(std::move(processor_2), std::make_shared<AlwaysOffSampler>()));
std::shared_ptr<Tracer> tracer_off(
new Tracer(std::move(processor_2), std::make_shared<AlwaysOffSampler>()));

auto t2 = tracer_off->GetSampler();
ASSERT_EQ("AlwaysOffSampler", t2->GetDescription());
}

TEST(Tracer, SpanSetAttribute)
{
std::shared_ptr<std::vector<std::unique_ptr<SpanData>>> spans_received(
new std::vector<std::unique_ptr<SpanData>>);
auto tracer = initTracer(spans_received);

auto span = tracer->StartSpan("span 1");

span->SetAttribute("abc", 3.1);

span->End();
ASSERT_EQ(1, spans_received->size());
auto &span_data = spans_received->at(0);
ASSERT_EQ(3.1, nostd::get<double>(span_data->GetAttributes().at("abc")));
}

0 comments on commit 2597ec8

Please sign in to comment.