Skip to content

Commit

Permalink
Add death tests for NOT_IMPLEMENTED methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
Reuven Lazarus committed May 25, 2017
1 parent 1e4ed13 commit 18fb3c2
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 3 deletions.
3 changes: 3 additions & 0 deletions test/mocks/ssl/mocks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ MockConnection::~MockConnection() {}
MockClientContext::MockClientContext() {}
MockClientContext::~MockClientContext() {}

MockServerContext::MockServerContext() {}
MockServerContext::~MockServerContext() {}

} // Ssl
} // Envoy
10 changes: 10 additions & 0 deletions test/mocks/ssl/mocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 16 additions & 0 deletions test/server/config_validation/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)

Expand All @@ -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 = [
Expand Down
17 changes: 16 additions & 1 deletion test/server/config_validation/connection_handler_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<Event::MockDispatcher>();
EXPECT_CALL(*api, allocateDispatcher_()).WillOnce(Return(dispatcher));
Expand All @@ -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<Network::MockFilterChainFactory> filter_factory;
NiceMock<Network::MockListenSocket> socket;
NiceMock<Stats::MockStore> scope;
Network::ListenerOptions options;
EXPECT_EXIT(handler.addListener(filter_factory, socket, scope, options), KilledBySignal(SIGABRT),
"not implemented");

NiceMock<Ssl::MockServerContext> server_context;
EXPECT_EXIT(handler.addSslListener(filter_factory, server_context, socket, scope, options),
KilledBySignal(SIGABRT), "not implemented");
}

} // Server
Expand Down
39 changes: 39 additions & 0 deletions test/server/config_validation/dispatcher_test.cc
Original file line number Diff line number Diff line change
@@ -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<Ssl::MockClientContext> client_context;
EXPECT_EXIT(dispatcher.createSslClientConnection(client_context, address),
KilledBySignal(SIGABRT), "not implemented");
EXPECT_EXIT(dispatcher.createDnsResolver(), KilledBySignal(SIGABRT), "not implemented");
NiceMock<Network::MockConnectionHandler> handler;
NiceMock<Network::MockListenSocket> socket;
NiceMock<Network::MockListenerCallbacks> callbacks;
NiceMock<Stats::MockStore> scope;
Network::ListenerOptions options;
EXPECT_EXIT(dispatcher.createListener(handler, socket, callbacks, scope, options),
KilledBySignal(SIGABRT), "not implemented");
NiceMock<Ssl::MockServerContext> server_context;
EXPECT_EXIT(
dispatcher.createSslListener(handler, server_context, socket, callbacks, scope, options),
KilledBySignal(SIGABRT), "not implemented");
}

} // Event
} // Envoy
33 changes: 31 additions & 2 deletions test/server/config_validation/server_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> {
public:
Expand Down Expand Up @@ -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<MockOptions> options("configs/google_com_proxy.json");
Stats::IsolatedStoreImpl store;
Thread::MutexBasicLockable access_log_lock;
TestComponentFactory component_factory;
NiceMock<LocalInfo::MockLocalInfo> 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

1 comment on commit 18fb3c2

@dnoe
Copy link
Contributor

@dnoe dnoe commented on 18fb3c2 May 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you get this to register the actual coverage of lines covered by the death tests? Last I checked the early but expected death inhibits the actual flush of coverage info.

Please sign in to comment.