浏览代码

Add tests to cover incomplete-style JSON Layout.

Sam Jaffe 5 年之前
父节点
当前提交
31f6c24078
共有 1 个文件被更改,包括 37 次插入1 次删除
  1. 37 1
      test/json_layout_test.cxx

+ 37 - 1
test/json_layout_test.cxx

@@ -223,7 +223,6 @@ TEST_F(JsonLayoutHeaderTest, ProvidesArrayBounds) {
 }
 
 TEST_F(JsonLayoutHeaderTest, SeparatesLogsWithComma) {
-  using testing::Eq;
   using testing::EndsWith;
   using testing::StartsWith;
   manager mgr;
@@ -236,3 +235,40 @@ TEST_F(JsonLayoutHeaderTest, SeparatesLogsWithComma) {
   // So the dividing comma gets attached to the next log
   EXPECT_THAT(appender->sstream.str(), StartsWith(",{"));
 }
+  
+struct JsonLayoutIncompleteTest : public JsonLayoutHeaderTest {
+  properties OVERRIDE{_obj({
+    {"configuration", _obj({
+      {"appenders", _obj({
+        {"Stub", _obj({
+          {"JsonLayout", _obj({
+            {"complete", _v(false)}
+          })}
+        })}
+      })}
+    })}
+  })};
+};
+
+TEST_F(JsonLayoutIncompleteTest, NoLogsMeansNoOutput) {
+  {
+    manager mgr;
+    mgr.configure(JSON_HEADER_SCHEMA.mergedWith(OVERRIDE));
+  }
+  using testing::Eq;
+  EXPECT_THAT(appender->sstream.str(), Eq(""));
+}
+  
+TEST_F(JsonLayoutIncompleteTest, NonCompleteLogProducesJsonPerLine) {
+  using testing::EndsWith;
+  using testing::StartsWith;
+  manager mgr;
+  mgr.configure(JSON_HEADER_SCHEMA.mergedWith(OVERRIDE));
+  mgr.get().log(level::error, "HELLO");
+  // Newline is printed as a part of the message...
+  EXPECT_THAT(appender->sstream.str(), EndsWith("}\n"));
+  appender->sstream.str("");
+  mgr.get().log(level::error, "HELLO");
+  // So the dividing comma gets attached to the next log
+  EXPECT_THAT(appender->sstream.str(), StartsWith("{"));
+}