]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/jaeger-client-cpp/src/jaegertracing/utils/ErrorUtilTest.cpp
2 * Copyright (c) 2017 Uber Technologies, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "jaegertracing/Logging.h"
18 #include "jaegertracing/Sender.h"
19 #include "jaegertracing/utils/ErrorUtil.h"
21 #include <gtest/gtest.h>
26 #include <system_error>
28 namespace jaegertracing
{
32 class TestLogger
: public logging::Logger
{
34 void info(const std::string
&) override
{}
36 void error(const std::string
& message
) override
{ _message
= message
; }
38 const std::string
& str() const { return _message
; }
44 bool endsWith(const std::string
& str
, const std::string
& suffix
)
46 if (str
.size() < suffix
.size()) {
51 std::begin(suffix
), std::end(suffix
), std::end(str
) - suffix
.size());
54 } // anonymous namespace
58 std::ostringstream oss
;
60 std::runtime_error
stdEx("runtime error");
61 std::system_error
sysEx(-1, std::generic_category());
62 Sender::Exception
transportEx("test", 5);
63 for (auto i
= 0; i
< 4; ++i
) {
77 ErrorUtil::logError(logger
, "test");
80 ASSERT_EQ("test: runtime error", logger
.str());
83 ASSERT_TRUE(endsWith(logger
.str(), ", code=-1"));
86 ASSERT_EQ("test: test, numFailed=5", logger
.str());
90 ASSERT_EQ("test", logger
.str());
98 } // namespace jaegertracing