forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.cc
99 lines (83 loc) · 3.52 KB
/
utils_test.cc
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "source/server/utils.h"
#include "test/mocks/server/options.h"
#include "test/test_common/utility.h"
#include "gtest/gtest.h"
using testing::Return;
namespace Envoy {
namespace Server {
namespace Utility {
// Most utils paths are covered through other tests, these tests take of
// of special cases to get remaining coverage.
TEST(UtilsTest, BadServerState) {
Utility::serverState(Init::Manager::State::Uninitialized, true);
EXPECT_ENVOY_BUG(Utility::serverState(static_cast<Init::Manager::State>(123), true),
"unexpected server state");
}
TEST(UtilsTest, AssertExclusiveLogFormatMethod) {
{
testing::NiceMock<MockOptions> options;
envoy::config::bootstrap::v3::Bootstrap::ApplicationLogConfig log_config;
EXPECT_TRUE(Utility::assertExclusiveLogFormatMethod(options, log_config).ok());
}
{
testing::NiceMock<MockOptions> options;
envoy::config::bootstrap::v3::Bootstrap::ApplicationLogConfig log_config;
EXPECT_CALL(options, logFormatSet()).WillRepeatedly(Return(true));
EXPECT_TRUE(Utility::assertExclusiveLogFormatMethod(options, log_config).ok());
}
{
testing::NiceMock<MockOptions> options;
envoy::config::bootstrap::v3::Bootstrap::ApplicationLogConfig log_config;
log_config.mutable_log_format();
EXPECT_TRUE(Utility::assertExclusiveLogFormatMethod(options, log_config).ok());
}
{
testing::NiceMock<MockOptions> options;
envoy::config::bootstrap::v3::Bootstrap::ApplicationLogConfig log_config;
EXPECT_CALL(options, logFormatSet()).WillRepeatedly(Return(true));
log_config.mutable_log_format();
EXPECT_EQ(
Utility::assertExclusiveLogFormatMethod(options, log_config).message(),
"Only one of ApplicationLogConfig.log_format or CLI option --log-format can be specified.");
}
}
TEST(UtilsTest, MaybeSetApplicationLogFormat) {
{
envoy::config::bootstrap::v3::Bootstrap::ApplicationLogConfig log_config;
EXPECT_TRUE(Utility::maybeSetApplicationLogFormat(log_config).ok());
}
{
envoy::config::bootstrap::v3::Bootstrap::ApplicationLogConfig log_config;
log_config.mutable_log_format();
EXPECT_TRUE(Utility::maybeSetApplicationLogFormat(log_config).ok());
}
{
envoy::config::bootstrap::v3::Bootstrap::ApplicationLogConfig log_config;
log_config.mutable_log_format()->mutable_json_format();
EXPECT_TRUE(Utility::maybeSetApplicationLogFormat(log_config).ok());
}
{
envoy::config::bootstrap::v3::Bootstrap::ApplicationLogConfig log_config;
log_config.mutable_log_format()->mutable_text_format();
EXPECT_TRUE(Utility::maybeSetApplicationLogFormat(log_config).ok());
}
{
envoy::config::bootstrap::v3::Bootstrap::ApplicationLogConfig log_config;
auto* format = log_config.mutable_log_format()->mutable_json_format();
format->mutable_fields()->operator[]("Message").set_string_value("%v");
EXPECT_EQ(Utility::maybeSetApplicationLogFormat(log_config).message(),
"setJsonLogFormat error: INVALID_ARGUMENT: Usage of %v is "
"unavailable for JSON log formats");
}
{
envoy::config::bootstrap::v3::Bootstrap::ApplicationLogConfig log_config;
auto* format = log_config.mutable_log_format()->mutable_json_format();
format->mutable_fields()->operator[]("Message").set_string_value("%_");
EXPECT_EQ(Utility::maybeSetApplicationLogFormat(log_config).message(),
"setJsonLogFormat error: INVALID_ARGUMENT: Usage of %_ is "
"unavailable for JSON log formats");
}
}
} // namespace Utility
} // namespace Server
} // namespace Envoy