Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Zhang committed Jun 22, 2020
1 parent fab9d74 commit fff8bda
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
11 changes: 11 additions & 0 deletions sdk/test/trace/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,14 @@ cc_test(
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "always_on_sampler_test",
srcs = [
"always_on_sampler_test.cc",
],
deps = [
"//sdk/src/trace",
"@com_google_googletest//:gtest_main",
],
)
37 changes: 37 additions & 0 deletions sdk/test/trace/always_on_sampler_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "opentelemetry/sdk/trace/always_on_sampler.h"
#include "opentelemetry/nostd/span.h"

#include <gtest/gtest.h>

using namespace opentelemetry::sdk::trace;
using namespace opentelemetry::nostd;

TEST(AlwaysOnSampler, ShouldSample)
{
AlwaysOnSampler sampler;

// A buffer of trace_id with no specific meaning
constexpr uint8_t buf[] = {0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7};

trace_api::TraceId trace_id_invalid;
trace_api::TraceId trace_id_valid(buf);

auto sampling_result = sampler.ShouldSample(nullptr, trace_id_invalid, "invalid trace id test",
trace_api::SpanKind::kServer, span<AttributeKeyValue>());

ASSERT_EQ(Decision::RECORD_AND_SAMPLE, sampling_result.decision);
ASSERT_EQ(0, sampling_result.attributes->size());

sampling_result = sampler.ShouldSample(nullptr, trace_id_valid, "valid trace id test",
trace_api::SpanKind::kServer, span<AttributeKeyValue>());

ASSERT_EQ(Decision::RECORD_AND_SAMPLE, sampling_result.decision);
ASSERT_EQ(0, sampling_result.attributes->size());
}

TEST(AlwaysOnSampler, GetDescription)
{
AlwaysOnSampler sampler;

ASSERT_EQ("AlwaysOnSampler", sampler.GetDescription());
}

0 comments on commit fff8bda

Please sign in to comment.