From 01a9488f6ea7074695bd3dd1dc32e7369dbd7a76 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 14 Jun 2020 20:20:14 +0200 Subject: [PATCH] add test for connect failure --- test/webfuse/tests/adapter/test_client.cc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/webfuse/tests/adapter/test_client.cc b/test/webfuse/tests/adapter/test_client.cc index 1002187..aa61867 100644 --- a/test/webfuse/tests/adapter/test_client.cc +++ b/test/webfuse/tests/adapter/test_client.cc @@ -124,6 +124,27 @@ TEST(AdapterClient, ConnectWithTls) ASSERT_TRUE(watcher.waitUntil([&]() mutable { return disconnected; })); } +TEST(AdapterClient, FailedToConnectInvalidPort) +{ + TimeoutWatcher watcher(TIMEOUT); + + + MockAdapterClientCallback callback; + EXPECT_CALL(callback, Invoke(_, WF_CLIENT_INIT, nullptr)).Times(1); + EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CREATED, nullptr)).Times(1); + EXPECT_CALL(callback, Invoke(_, WF_CLIENT_GET_TLS_CONFIG, _)).Times(1); + EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CLEANUP, nullptr)).Times(1); + + bool disconnected = false; + EXPECT_CALL(callback, Invoke(_, WF_CLIENT_DISCONNECTED, nullptr)).Times(1) + .WillOnce(Invoke([&] (wf_client *, int, void *) mutable { disconnected = true; })); + + AdapterClient client(callback.GetCallbackFn(), callback.GetUserData(), "ws://localhost:4/"); + + client.Connect(); + ASSERT_TRUE(watcher.waitUntil([&]() mutable { return disconnected; })); +} + TEST(AdapterClient, Authenticate) {