Skip to content

Commit

Permalink
renamed some variables, added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
satac2 committed Jun 10, 2020
1 parent 2d4a411 commit 9874c4c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
1 change: 1 addition & 0 deletions api/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
add_subdirectory(core)
add_subdirectory(context)
add_subdirectory(plugin)
add_subdirectory(nostd)
add_subdirectory(trace)
4 changes: 0 additions & 4 deletions api/test/context/context_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,3 @@ TEST(Context_test, context_write_new_object)
EXPECT_EQ(new_test_context.GetValue(foo_key), 1);
}





37 changes: 31 additions & 6 deletions api/test/context/runtimeContext_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@

using namespace opentelemetry::context;


/* Tests whether the runtimeContext object properly returns the current context
*/
TEST(runtimeContext_test, get_current_context)
{

Context::ContextKey test_key = Context::ContextKey("test_key");
Context test_context = Context(test_key, 7);

RuntimeContext test_runtime = RuntimeContext(test_context);

EXPECT_EQ(test_runtime.GetCurrent().GetValue(test_key),
test_context.GetValue(test_key));

}




/* Tests whether the runtimeContext object properly attaches and detaches
* the context object.
*/
Expand All @@ -18,17 +37,23 @@ TEST(runtimeContext_test, attach_detach_context)
Context::ContextKey foo_key = Context::ContextKey("foo_key");
Context foo_context = Context(foo_key, 5);

EXPECT_EQ(test_runtime.GetCurrent().GetValue(test_key), test_context.GetValue(test_key));
EXPECT_NE(test_runtime.GetCurrent().GetValue(foo_key), foo_context.GetValue(foo_key));
EXPECT_EQ(test_runtime.GetCurrent().GetValue(test_key),
test_context.GetValue(test_key));
EXPECT_NE(test_runtime.GetCurrent().GetValue(foo_key),
foo_context.GetValue(foo_key));

Token test_token = test_runtime.Attach(foo_context);

EXPECT_NE(test_runtime.GetCurrent().GetValue(test_key), test_context.GetValue(test_key));
EXPECT_EQ(test_runtime.GetCurrent().GetValue(foo_key), foo_context.GetValue(foo_key));
EXPECT_NE(test_runtime.GetCurrent().GetValue(test_key),
test_context.GetValue(test_key));
EXPECT_EQ(test_runtime.GetCurrent().GetValue(foo_key),
foo_context.GetValue(foo_key));

test_runtime.Detach(test_token);

EXPECT_EQ(test_runtime.GetCurrent().GetValue(test_key), test_context.GetValue(test_key));
EXPECT_NE(test_runtime.GetCurrent().GetValue(foo_key), foo_context.GetValue(foo_key));
EXPECT_EQ(test_runtime.GetCurrent().GetValue(test_key),
test_context.GetValue(test_key));
EXPECT_NE(test_runtime.GetCurrent().GetValue(foo_key),
foo_context.GetValue(foo_key));
}

0 comments on commit 9874c4c

Please sign in to comment.