json_layout_test.cxx 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //
  2. // json_layout_test.cxx
  3. // logger_test
  4. //
  5. // Created by Sam Jaffe on 4/13/19.
  6. //
  7. #include <gmock/gmock.h>
  8. #include "resource_factory/prototype_factory.hpp"
  9. #include "logger/detail/layout.h"
  10. #include "logger/log_manager.h"
  11. #include "logger/logpacket.h"
  12. #include "logger/properties.h"
  13. TEST(JsonLayoutTest, CanConstructWithNoConfig) {
  14. EXPECT_NO_THROW(logging::layouts::instance().get("JsonLayout", {}));
  15. }
  16. // Thursday, April 4, 2019 6:17:20 PM GMT
  17. namespace {
  18. constexpr const int NOW = 1554401840;
  19. }
  20. std::string const formatted_output = R"({
  21. "instant": {
  22. "epochSecond": 1554401840,
  23. "nanoOfSecond": 123456000
  24. }
  25. "level": "warning",
  26. "loggerName": "UnitTest",
  27. "message": "This is a test message"
  28. })";
  29. TEST(JsonLayoutTest, TestInvokesFormatter) {
  30. using namespace logging;
  31. auto playout = layouts::instance().get("JsonLayout", {});
  32. std::stringstream ss;
  33. playout->format(ss, {{NOW, 123456}, level::warning, {}, "UnitTest",
  34. "This is a test message"});
  35. using testing::Eq;
  36. EXPECT_THAT(ss.str(), Eq(formatted_output));
  37. }