forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_runner.h
48 lines (40 loc) · 1.83 KB
/
test_runner.h
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
#include "common/common/logger.h"
#include "common/common/logger_delegates.h"
#include "common/common/thread.h"
#include "common/event/libevent.h"
#include "test/mocks/access_log/mocks.h"
#include "test/test_common/environment.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
namespace Envoy {
class TestRunner {
public:
static int RunTests(int argc, char** argv) {
::testing::InitGoogleMock(&argc, argv);
Event::Libevent::Global::initialize();
// Set gtest properties
// (https://github.com/google/googletest/blob/master/googletest/docs/AdvancedGuide.md#logging-additional-information),
// they are available in the test XML.
// TODO(htuch): Log these as well?
::testing::Test::RecordProperty("TemporaryDirectory", TestEnvironment::temporaryDirectory());
::testing::Test::RecordProperty("RunfilesDirectory", TestEnvironment::runfilesDirectory());
if (::setenv("TEST_UDSDIR", TestEnvironment::unixDomainSocketDirectory().c_str(), 1) != 0) {
::perror("Failed to set temporary UDS directory.");
::exit(1);
}
TestEnvironment::initializeOptions(argc, argv);
Thread::MutexBasicLockable lock;
Logger::Context logging_state(TestEnvironment::getOptions().logLevel(),
TestEnvironment::getOptions().logFormat(), lock);
// Allocate fake log access manager.
testing::NiceMock<AccessLog::MockAccessLogManager> access_log_manager;
std::unique_ptr<Logger::FileSinkDelegate> file_logger;
// Redirect all logs to fake file when --log-path arg is specified in command line.
if (!TestEnvironment::getOptions().logPath().empty()) {
file_logger = std::make_unique<Logger::FileSinkDelegate>(
TestEnvironment::getOptions().logPath(), access_log_manager, Logger::Registry::getSink());
}
return RUN_ALL_TESTS();
}
};
} // namespace Envoy