summaryrefslogtreecommitdiffstats
path: root/src/test/common/test_journald_logger.cc
blob: cf8df6dbca2c035f4d627c37b3696302346470b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#include <cerrno>
#include <gtest/gtest.h>
#include <sys/stat.h>

#include "common/Journald.h"
#include "log/Entry.h"
#include "log/SubsystemMap.h"

using namespace ceph::logging;

class JournaldLoggerTest : public ::testing::Test {
 protected:
  SubsystemMap subs;
  JournaldLogger journald = {&subs};
  MutableEntry entry = {0, 0};

  void SetUp() override {
    struct stat buffer;
    if (stat("/run/systemd/journal/socket", &buffer) < 0) {
      if (errno == ENOENT) {
        GTEST_SKIP() << "No journald socket present.";
      }
      FAIL() << "Unexpected stat error: " << strerror(errno);
    }
  }
};

TEST_F(JournaldLoggerTest, Log)
{
  entry.get_ostream() << "This is a testing regular log message.";
  EXPECT_EQ(journald.log_entry(entry), 0);
}

TEST_F(JournaldLoggerTest, VeryLongLog)
{
  entry.get_ostream() << std::string(16 * 1024 * 1024, 'a');
  EXPECT_EQ(journald.log_entry(entry), 0);
}