Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ostream_log_test Mac #1208

Merged
merged 2 commits into from
Feb 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 74 additions & 56 deletions exporters/ostream/test/ostream_log_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,27 @@ TEST(OstreamLogExporter, DefaultLogRecordToCout)
// Restore cout's original stringstream
std::cout.rdbuf(original);

std::string expectedOutput =
std::vector<std::string> expected_output{
"{\n"
" timestamp : 0\n"
" severity_num : 0\n"
" severity_text : INVALID\n"
" name : \n"
" body : \n"
" resource : {{telemetry.sdk.version: " OPENTELEMETRY_VERSION
"}, {telemetry.sdk.name: opentelemetry}, {telemetry.sdk.language: cpp}}\n"
" body : \n",
" resource : {",
"{telemetry.sdk.version: " OPENTELEMETRY_VERSION "}",
"{telemetry.sdk.name: opentelemetry}",
"{telemetry.sdk.language: cpp}",
" attributes : {}\n"
" trace_id : 00000000000000000000000000000000\n"
" span_id : 0000000000000000\n"
" trace_flags : 00\n"
"}\n";
"}\n"};

ASSERT_EQ(output.str(), expectedOutput);
for (auto &expected : expected_output)
{
ASSERT_NE(output.str().find(expected), std::string::npos);
}
}

// Testing what a log record with only the "timestamp", "severity", "name" and "message" fields set,
Expand Down Expand Up @@ -121,24 +126,29 @@ TEST(OStreamLogExporter, SimpleLogToCout)
// Reset cout's original stringstream buffer
std::cout.rdbuf(original);

std::string expectedOutput =
std::vector<std::string> expected_output{
"{\n"
" timestamp : " +
std::to_string(now.time_since_epoch().count()) +
"\n"
" severity_num : 1\n"
" severity_text : TRACE\n"
" name : Name\n"
" body : Message\n"
" resource : {{telemetry.sdk.version: " OPENTELEMETRY_VERSION
"}, {telemetry.sdk.name: opentelemetry}, "
"{telemetry.sdk.language: cpp}}\n"
std::to_string(now.time_since_epoch().count()) +
"\n"
" severity_num : 1\n"
" severity_text : TRACE\n"
" name : Name\n"
" body : Message\n",
" resource : {",
"{telemetry.sdk.version: " OPENTELEMETRY_VERSION "}",
"{telemetry.sdk.name: opentelemetry}",
"{telemetry.sdk.language: cpp}",
" attributes : {}\n"
" trace_id : 00000000000000000000000000000000\n"
" span_id : 0000000000000000\n"
" trace_flags : 00\n"
"}\n";
ASSERT_EQ(output.str(), expectedOutput);
"}\n"};

for (auto &expected : expected_output)
{
ASSERT_NE(output.str().find(expected), std::string::npos);
}
}

// ---------------------------------- Print to cerr --------------------------
Expand Down Expand Up @@ -172,26 +182,29 @@ TEST(OStreamLogExporter, LogWithStringAttributesToCerr)
// Reset cerr's original stringstream buffer
std::cerr.rdbuf(original);

std::string expectedOutput =
std::vector<std::string> expected_output{
"{\n"
" timestamp : 0\n"
" severity_num : 0\n"
" severity_text : INVALID\n"
" name : \n"
" body : \n"
" resource : {{telemetry.sdk.version: " OPENTELEMETRY_VERSION
"}, {telemetry.sdk.name: opentelemetry}, {telemetry.sdk.language: cpp}, {service.name: "
"unknown_service}, {key1: val1}}\n"
" body : \n",
" resource : {",
"{telemetry.sdk.version: " OPENTELEMETRY_VERSION "}",
"{telemetry.sdk.name: opentelemetry}",
"{telemetry.sdk.language: cpp}",
"{service.name: unknown_service}",
"{key1: val1}",
" attributes : {{a: 1}}\n"
" trace_id : 00000000000000000000000000000000\n"
" span_id : 0000000000000000\n"
" trace_flags : 00\n"
"}\n";
// TODO this test fails on Mac
// issue https://github.com/open-telemetry/opentelemetry-cpp/issues/1187
# if !defined(__APPLE__)
ASSERT_EQ(stdcerrOutput.str(), expectedOutput);
# endif
"}\n"};

for (auto &expected : expected_output)
{
ASSERT_NE(stdcerrOutput.str().find(expected), std::string::npos);
}
}

// ---------------------------------- Print to clog -------------------------
Expand Down Expand Up @@ -231,26 +244,29 @@ TEST(OStreamLogExporter, LogWithVariantTypesToClog)
// Reset clog's original stringstream buffer
std::clog.rdbuf(original);

std::string expectedOutput =
std::vector<std::string> expected_output{
"{\n"
" timestamp : 0\n"
" severity_num : 0\n"
" severity_text : INVALID\n"
" name : \n"
" body : \n"
" resource : {{service.name: unknown_service}, "
"{telemetry.sdk.version: " OPENTELEMETRY_VERSION
"}, {telemetry.sdk.name: opentelemetry}, {telemetry.sdk.language: cpp}, {res1: [1, 2, 3]}}\n"
" body : \n",
" resource : {",
"{service.name: unknown_service}",
"{telemetry.sdk.version: " OPENTELEMETRY_VERSION "}",
"{telemetry.sdk.name: opentelemetry}",
"{telemetry.sdk.language: cpp}",
"{res1: [1, 2, 3]}",
" attributes : {{attr1: [0, 1, 0]}}\n"
" trace_id : 00000000000000000000000000000000\n"
" span_id : 0000000000000000\n"
" trace_flags : 00\n"
"}\n";
// TODO this test fails on Mac
// issue https://github.com/open-telemetry/opentelemetry-cpp/issues/1187
# if !defined(__APPLE__)
ASSERT_EQ(stdclogOutput.str(), expectedOutput);
# endif
"}\n"};

for (auto &expected : expected_output)
{
ASSERT_NE(stdclogOutput.str().find(expected), std::string::npos);
}
}

// // ---------------------------------- Integration Tests -------------------------
Expand Down Expand Up @@ -286,28 +302,30 @@ TEST(OStreamLogExporter, IntegrationTest)
std::cout.rdbuf(original);

// Compare actual vs expected outputs
std::string expectedOutput =
std::vector<std::string> expected_output{
"{\n"
" timestamp : " +
std::to_string(now.time_since_epoch().count()) +
"\n"
" severity_num : 5\n"
" severity_text : DEBUG\n"
" name : \n"
" body : Hello\n"
" resource : {{service.name: unknown_service}, "
"{telemetry.sdk.version: " OPENTELEMETRY_VERSION
"}, {telemetry.sdk.name: opentelemetry}, {telemetry.sdk.language: cpp}}\n"
std::to_string(now.time_since_epoch().count()) +
"\n"
" severity_num : 5\n"
" severity_text : DEBUG\n"
" name : \n"
" body : Hello\n",
" resource : {",
"{telemetry.sdk.version: " OPENTELEMETRY_VERSION "}",
"{service.name: unknown_service}",
"{telemetry.sdk.name: opentelemetry}",
"{telemetry.sdk.language: cpp}",
" attributes : {}\n"
" trace_id : 00000000000000000000000000000000\n"
" span_id : 0000000000000000\n"
" trace_flags : 00\n"
"}\n";
// TODO this test fails on Mac
// issue https://github.com/open-telemetry/opentelemetry-cpp/issues/1187
# if !defined(__APPLE__)
ASSERT_EQ(stdcoutOutput.str(), expectedOutput);
# endif
"}\n"};

for (auto &expected : expected_output)
{
ASSERT_NE(stdcoutOutput.str().find(expected), std::string::npos);
}
}

} // namespace logs
Expand Down