From 18fb3c2c492e1d06de189a04e4e4a6967bde0122 Mon Sep 17 00:00:00 2001 From: Reuven Lazarus Date: Thu, 25 May 2017 12:42:27 -0400 Subject: [PATCH] Add death tests for NOT_IMPLEMENTED methods. --- test/mocks/ssl/mocks.cc | 3 ++ test/mocks/ssl/mocks.h | 10 +++++ test/server/config_validation/BUILD | 16 ++++++++ .../connection_handler_test.cc | 17 +++++++- .../config_validation/dispatcher_test.cc | 39 +++++++++++++++++++ test/server/config_validation/server_test.cc | 33 +++++++++++++++- 6 files changed, 115 insertions(+), 3 deletions(-) create mode 100644 test/server/config_validation/dispatcher_test.cc diff --git a/test/mocks/ssl/mocks.cc b/test/mocks/ssl/mocks.cc index 2b4cf8848b94..63edf1c4dba9 100644 --- a/test/mocks/ssl/mocks.cc +++ b/test/mocks/ssl/mocks.cc @@ -12,5 +12,8 @@ MockConnection::~MockConnection() {} MockClientContext::MockClientContext() {} MockClientContext::~MockClientContext() {} +MockServerContext::MockServerContext() {} +MockServerContext::~MockServerContext() {} + } // Ssl } // Envoy diff --git a/test/mocks/ssl/mocks.h b/test/mocks/ssl/mocks.h index 2c0a3c334afe..cb32ae8499c1 100755 --- a/test/mocks/ssl/mocks.h +++ b/test/mocks/ssl/mocks.h @@ -52,5 +52,15 @@ class MockClientContext : public ClientContext { MOCK_METHOD0(getCertChainInformation, std::string()); }; +class MockServerContext : public ServerContext { +public: + MockServerContext(); + ~MockServerContext(); + + MOCK_METHOD0(daysUntilFirstCertExpires, size_t()); + MOCK_METHOD0(getCaCertInformation, std::string()); + MOCK_METHOD0(getCertChainInformation, std::string()); +}; + } // Ssl } // Envoy diff --git a/test/server/config_validation/BUILD b/test/server/config_validation/BUILD index 0147bb8fcb4d..690fb3f54dc3 100644 --- a/test/server/config_validation/BUILD +++ b/test/server/config_validation/BUILD @@ -47,6 +47,21 @@ envoy_cc_test( "//source/server/config_validation:connection_handler_lib", "//test/mocks/api:api_mocks", "//test/mocks/event:event_mocks", + "//test/mocks/network:network_mocks", + "//test/mocks/ssl:ssl_mocks", + "//test/mocks/stats:stats_mocks", + ], +) + +envoy_cc_test( + name = "dispatcher_test", + srcs = ["dispatcher_test.cc"], + deps = [ + "//source/common/network:address_lib", + "//source/server/config_validation:dispatcher_lib", + "//test/mocks/network:network_mocks", + "//test/mocks/ssl:ssl_mocks", + "//test/mocks/stats:stats_mocks", ], ) @@ -55,6 +70,7 @@ envoy_cc_test( srcs = ["server_test.cc"], data = [ "//configs:example_configs", + "//configs:google_com_proxy.json", "//test/config_test:example_configs_test_setup.sh", ], deps = [ diff --git a/test/server/config_validation/connection_handler_test.cc b/test/server/config_validation/connection_handler_test.cc index 6772c40b103b..5e37e82de3e1 100644 --- a/test/server/config_validation/connection_handler_test.cc +++ b/test/server/config_validation/connection_handler_test.cc @@ -6,14 +6,18 @@ #include "test/mocks/api/mocks.h" #include "test/mocks/event/mocks.h" +#include "test/mocks/network/mocks.h" +#include "test/mocks/ssl/mocks.h" +#include "test/mocks/stats/mocks.h" namespace Envoy { namespace Server { +using testing::KilledBySignal; using testing::NiceMock; using testing::Return; -TEST(ValidationConnectionHandlerTest, MockedMethods) { +TEST(ValidationConnectionHandlerDeathTest, MockedMethods) { Api::MockApi* api = new Api::MockApi(); Event::MockDispatcher* dispatcher = new NiceMock(); EXPECT_CALL(*api, allocateDispatcher_()).WillOnce(Return(dispatcher)); @@ -23,6 +27,17 @@ TEST(ValidationConnectionHandlerTest, MockedMethods) { Network::Address::Ipv4Instance address("0.0.0.0", 0); EXPECT_EQ(nullptr, handler.findListenerByAddress(address)); EXPECT_NO_THROW(handler.closeListeners()); + + NiceMock filter_factory; + NiceMock socket; + NiceMock scope; + Network::ListenerOptions options; + EXPECT_EXIT(handler.addListener(filter_factory, socket, scope, options), KilledBySignal(SIGABRT), + "not implemented"); + + NiceMock server_context; + EXPECT_EXIT(handler.addSslListener(filter_factory, server_context, socket, scope, options), + KilledBySignal(SIGABRT), "not implemented"); } } // Server diff --git a/test/server/config_validation/dispatcher_test.cc b/test/server/config_validation/dispatcher_test.cc new file mode 100644 index 000000000000..438eff836298 --- /dev/null +++ b/test/server/config_validation/dispatcher_test.cc @@ -0,0 +1,39 @@ +#include "common/network/address_impl.h" + +#include "server/config_validation/dispatcher.h" + +#include "test/mocks/network/mocks.h" +#include "test/mocks/ssl/mocks.h" +#include "test/mocks/stats/mocks.h" + +namespace Envoy { +namespace Event { + +using testing::KilledBySignal; +using testing::NiceMock; + +TEST(ValidationDispatcherTest, UnimplementedMethods) { + ValidationDispatcher dispatcher; + Network::Address::InstanceConstSharedPtr address{ + new Network::Address::Ipv4Instance("0.0.0.0", 0)}; + EXPECT_EXIT(dispatcher.createClientConnection(address), KilledBySignal(SIGABRT), + "not implemented"); + NiceMock client_context; + EXPECT_EXIT(dispatcher.createSslClientConnection(client_context, address), + KilledBySignal(SIGABRT), "not implemented"); + EXPECT_EXIT(dispatcher.createDnsResolver(), KilledBySignal(SIGABRT), "not implemented"); + NiceMock handler; + NiceMock socket; + NiceMock callbacks; + NiceMock scope; + Network::ListenerOptions options; + EXPECT_EXIT(dispatcher.createListener(handler, socket, callbacks, scope, options), + KilledBySignal(SIGABRT), "not implemented"); + NiceMock server_context; + EXPECT_EXIT( + dispatcher.createSslListener(handler, server_context, socket, callbacks, scope, options), + KilledBySignal(SIGABRT), "not implemented"); +} + +} // Event +} // Envoy diff --git a/test/server/config_validation/server_test.cc b/test/server/config_validation/server_test.cc index 4523fbf082cc..a9b2d5829ce5 100644 --- a/test/server/config_validation/server_test.cc +++ b/test/server/config_validation/server_test.cc @@ -8,6 +8,9 @@ namespace Envoy { namespace Server { +using testing::KilledBySignal; +using testing::Values; + // Test param is the path to the config file to validate. class ValidationServerTest : public testing::TestWithParam { public: @@ -38,8 +41,34 @@ TEST_P(ValidationServerTest, Validate) { // the filesystem for TLS certs, etc. In the meantime, these are the example configs that work // as-is. INSTANTIATE_TEST_CASE_P(ValidConfigs, ValidationServerTest, - ::testing::Values("front-envoy.json", "google_com_proxy.json", - "s2s-grpc-envoy.json", "service-envoy.json")); + Values("front-envoy.json", "google_com_proxy.json", "s2s-grpc-envoy.json", + "service-envoy.json")); + +TEST(ValidationServerDeathTest, UnimplementedMethods) { + NiceMock options("configs/google_com_proxy.json"); + Stats::IsolatedStoreImpl store; + Thread::MutexBasicLockable access_log_lock; + TestComponentFactory component_factory; + NiceMock local_info; + + ValidationInstance server(options, store, access_log_lock, component_factory, local_info); + EXPECT_EXIT(server.admin(), KilledBySignal(SIGABRT), "not implemented"); + EXPECT_EXIT(server.draining(), KilledBySignal(SIGABRT), "not implemented"); + EXPECT_EXIT(server.drainListeners(), KilledBySignal(SIGABRT), "not implemented"); + EXPECT_EXIT(server.drainManager(), KilledBySignal(SIGABRT), "not implemented"); + EXPECT_EXIT(server.failHealthcheck(true), KilledBySignal(SIGABRT), "not implemented"); + EXPECT_EXIT(server.getListenSocketFd(""), KilledBySignal(SIGABRT), "not implemented"); + EXPECT_EXIT(server.getListenSocketByIndex(0), KilledBySignal(SIGABRT), "not implemented"); + HotRestart::GetParentStatsInfo info; + EXPECT_EXIT(server.getParentStats(info), KilledBySignal(SIGABRT), "not implemented"); + EXPECT_EXIT(server.hotRestart(), KilledBySignal(SIGABRT), "not implemented"); + EXPECT_EXIT(server.shutdownAdmin(), KilledBySignal(SIGABRT), "not implemented"); + EXPECT_EXIT(server.healthCheckFailed(), KilledBySignal(SIGABRT), "not implemented"); + EXPECT_EXIT(server.startTimeCurrentEpoch(), KilledBySignal(SIGABRT), "not implemented"); + EXPECT_EXIT(server.startTimeFirstEpoch(), KilledBySignal(SIGABRT), "not implemented"); + + server.shutdown(); +} } // Server } // Envoy