]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/common/test_journald_logger.cc
import quincy beta 17.1.0
[ceph.git] / ceph / src / test / common / test_journald_logger.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #include <cerrno>
5 #include <gtest/gtest.h>
6 #include <sys/stat.h>
7
8 #include "common/Journald.h"
9 #include "log/Entry.h"
10 #include "log/SubsystemMap.h"
11
12 using namespace ceph::logging;
13
14 class JournaldLoggerTest : public ::testing::Test {
15 protected:
16 SubsystemMap subs;
17 JournaldLogger journald = {&subs};
18 MutableEntry entry = {0, 0};
19
20 void SetUp() override {
21 struct stat buffer;
22 if (stat("/run/systemd/journal/socket", &buffer) < 0) {
23 if (errno == ENOENT) {
24 GTEST_SKIP() << "No journald socket present.";
25 }
26 FAIL() << "Unexpected stat error: " << strerror(errno);
27 }
28 }
29 };
30
31 TEST_F(JournaldLoggerTest, Log)
32 {
33 entry.get_ostream() << "This is a testing regular log message.";
34 EXPECT_EQ(journald.log_entry(entry), 0);
35 }
36
37 TEST_F(JournaldLoggerTest, VeryLongLog)
38 {
39 entry.get_ostream() << std::string(16 * 1024 * 1024, 'a');
40 EXPECT_EQ(journald.log_entry(entry), 0);
41 }