Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
228 changes: 227 additions & 1 deletion test/mocks/upstream/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,38 @@ envoy_cc_mock(

envoy_cc_mock(
name = "upstream_mocks",
srcs = ["mocks.cc"],
hdrs = ["mocks.h"],
deps = [
":basic_resource_limit_mocks",
":cds_api_mocks",
":cluster_info_factory_mocks",
":cluster_manager_factory_mocks",
":cluster_manager_mocks",
":cluster_mocks",
":cluster_priority_set_mocks",
":cluster_real_priority_set_mocks",
":cluster_update_callbacks_handle_mocks",
":cluster_update_callbacks_mocks",
":health_check_event_logger_mocks",
":health_checker_mocks",
":host_set_mocks",
":load_balancer_context_mock",
":load_balancer_mocks",
":priority_set_mocks",
":retry_host_predicate_mocks",
":retry_priority_factory_mocks",
":retry_priority_mocks",
":test_retry_host_predicate_factory_mocks",
":thread_aware_load_balancer_mocks",
":thread_local_cluster_mocks",
":transport_socket_match_mocks",
"//include/envoy/http:async_client_interface",
"//include/envoy/upstream:cluster_factory_interface",
"//include/envoy/upstream:cluster_manager_interface",
"//include/envoy/upstream:health_checker_interface",
"//include/envoy/upstream:load_balancer_interface",
"//include/envoy/upstream:upstream_interface",
"//source/common/http:header_utility_lib",
"//source/common/upstream:cluster_factory_lib",
"//source/common/upstream:health_discovery_service_lib",
"//source/common/upstream:upstream_lib",
Expand All @@ -96,3 +117,208 @@ envoy_cc_mock(
"@envoy_api//envoy/data/core/v3:pkg_cc_proto",
],
)

envoy_cc_mock(
name = "host_set_mocks",
srcs = ["host_set.cc"],
hdrs = ["host_set.h"],
deps = [
"//include/envoy/upstream:upstream_interface",
"//source/common/common:callback_impl_lib",
"//source/common/upstream:upstream_lib",
],
)

envoy_cc_mock(
name = "priority_set_mocks",
srcs = ["priority_set.cc"],
hdrs = ["priority_set.h"],
deps = [
"//include/envoy/upstream:upstream_interface",
"//test/mocks/upstream:host_set_mocks",
],
)

envoy_cc_mock(
name = "retry_priority_mocks",
srcs = ["retry_priority.cc"],
hdrs = ["retry_priority.h"],
deps = [
"//include/envoy/upstream:retry_interface",
],
)

envoy_cc_mock(
name = "retry_priority_factory_mocks",
hdrs = ["retry_priority_factory.h"],
deps = [
"//include/envoy/upstream:retry_interface",
"//test/mocks/upstream:retry_priority_mocks",
],
)

envoy_cc_mock(
name = "cluster_mocks",
srcs = ["cluster.cc"],
hdrs = ["cluster.h"],
deps = [
"//include/envoy/upstream:upstream_interface",
"//test/mocks/upstream:cluster_info_mocks",
],
)

envoy_cc_mock(
name = "cluster_real_priority_set_mocks",
srcs = ["cluster_real_priority_set.cc"],
hdrs = ["cluster_real_priority_set.h"],
deps = [
"//test/mocks/upstream:cluster_mocks",
],
)

envoy_cc_mock(
name = "cluster_priority_set_mocks",
srcs = ["cluster_priority_set.cc"],
hdrs = ["cluster_priority_set.h"],
deps = [
"//test/mocks/upstream:cluster_mocks",
"//test/mocks/upstream:priority_set_mocks",
],
)

envoy_cc_mock(
name = "load_balancer_mocks",
srcs = ["load_balancer.cc"],
hdrs = ["load_balancer.h"],
deps = [
"//include/envoy/upstream:load_balancer_interface",
"//test/mocks/upstream:host_mocks",
],
)

envoy_cc_mock(
name = "thread_aware_load_balancer_mocks",
srcs = ["thread_aware_load_balancer.cc"],
hdrs = ["thread_aware_load_balancer.h"],
deps = [
"//include/envoy/upstream:load_balancer_interface",
],
)

envoy_cc_mock(
name = "thread_local_cluster_mocks",
srcs = ["thread_local_cluster.cc"],
hdrs = ["thread_local_cluster.h"],
deps = [
"//include/envoy/upstream:thread_local_cluster_interface",
"//test/mocks/upstream:cluster_priority_set_mocks",
"//test/mocks/upstream:load_balancer_mocks",
],
)

envoy_cc_mock(
name = "cluster_manager_factory_mocks",
srcs = ["cluster_manager_factory.cc"],
hdrs = ["cluster_manager_factory.h"],
deps = [
"//include/envoy/upstream:cluster_manager_interface",
"//test/mocks/secret:secret_mocks",
],
)

envoy_cc_mock(
name = "cluster_update_callbacks_handle_mocks",
srcs = ["cluster_update_callbacks_handle.cc"],
hdrs = ["cluster_update_callbacks_handle.h"],
deps = [
"//include/envoy/upstream:cluster_manager_interface",
],
)

envoy_cc_mock(
name = "cluster_manager_mocks",
srcs = ["cluster_manager.cc"],
hdrs = ["cluster_manager.h"],
deps = [
"//include/envoy/upstream:cluster_manager_interface",
"//test/mocks/config:config_mocks",
"//test/mocks/grpc:grpc_mocks",
"//test/mocks/http:http_mocks",
"//test/mocks/tcp:tcp_mocks",
"//test/mocks/upstream:cluster_manager_factory_mocks",
"//test/mocks/upstream:thread_local_cluster_mocks",
],
)

envoy_cc_mock(
name = "health_checker_mocks",
srcs = ["health_checker.cc"],
hdrs = ["health_checker.h"],
deps = [
"//include/envoy/upstream:health_checker_interface",
],
)

envoy_cc_mock(
name = "health_check_event_logger_mocks",
hdrs = ["health_check_event_logger.h"],
deps = [
"//include/envoy/upstream:health_checker_interface",
"@envoy_api//envoy/data/core/v3:pkg_cc_proto",
],
)

envoy_cc_mock(
name = "cds_api_mocks",
srcs = ["cds_api.cc"],
hdrs = ["cds_api.h"],
deps = [
"//include/envoy/upstream:cluster_manager_interface",
],
)

envoy_cc_mock(
name = "cluster_update_callbacks_mocks",
srcs = ["cluster_update_callbacks.cc"],
hdrs = ["cluster_update_callbacks.h"],
deps = [
"//include/envoy/upstream:cluster_manager_interface",
],
)

envoy_cc_mock(
name = "cluster_info_factory_mocks",
srcs = ["cluster_info_factory.cc"],
hdrs = ["cluster_info_factory.h"],
deps = [
"//include/envoy/upstream:cluster_manager_interface",
"//source/common/common:minimal_logger_lib",
],
)

envoy_cc_mock(
name = "retry_host_predicate_mocks",
srcs = ["retry_host_predicate.cc"],
hdrs = ["retry_host_predicate.h"],
deps = [
"//include/envoy/upstream:retry_interface",
],
)

envoy_cc_mock(
name = "test_retry_host_predicate_factory_mocks",
hdrs = ["test_retry_host_predicate_factory.h"],
deps = [
"//include/envoy/upstream:retry_interface",
"//test/mocks/upstream:retry_host_predicate_mocks",
],
)

envoy_cc_mock(
name = "basic_resource_limit_mocks",
srcs = ["basic_resource_limit.cc"],
hdrs = ["basic_resource_limit.h"],
deps = [
"//include/envoy/common:resource_interface",
],
)
17 changes: 17 additions & 0 deletions test/mocks/upstream/basic_resource_limit.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "basic_resource_limit.h"

#include "gmock/gmock.h"
#include "gtest/gtest.h"

namespace Envoy {
namespace Upstream {

using ::testing::Return;
MockBasicResourceLimit::MockBasicResourceLimit() {
ON_CALL(*this, canCreate()).WillByDefault(Return(true));
}

MockBasicResourceLimit::~MockBasicResourceLimit() = default;

} // namespace Upstream
} // namespace Envoy
23 changes: 23 additions & 0 deletions test/mocks/upstream/basic_resource_limit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include "envoy/common/resource.h"

#include "gmock/gmock.h"
#include "gtest/gtest.h"

namespace Envoy {
namespace Upstream {
class MockBasicResourceLimit : public ResourceLimit {
public:
MockBasicResourceLimit();
~MockBasicResourceLimit() override;

MOCK_METHOD(bool, canCreate, ());
MOCK_METHOD(void, inc, ());
MOCK_METHOD(void, dec, ());
MOCK_METHOD(void, decBy, (uint64_t));
MOCK_METHOD(uint64_t, max, ());
MOCK_METHOD(uint64_t, count, (), (const));
};
} // namespace Upstream
} // namespace Envoy
19 changes: 19 additions & 0 deletions test/mocks/upstream/cds_api.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "cds_api.h"

#include <functional>

#include "gmock/gmock.h"
#include "gtest/gtest.h"

namespace Envoy {
namespace Upstream {
using ::testing::_;
using ::testing::SaveArg;
MockCdsApi::MockCdsApi() {
ON_CALL(*this, setInitializedCb(_)).WillByDefault(SaveArg<0>(&initialized_callback_));
}

MockCdsApi::~MockCdsApi() = default;

} // namespace Upstream
} // namespace Envoy
25 changes: 25 additions & 0 deletions test/mocks/upstream/cds_api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#include <functional>
#include <string>

#include "envoy/upstream/cluster_manager.h"

#include "gmock/gmock.h"
#include "gtest/gtest.h"

namespace Envoy {
namespace Upstream {
class MockCdsApi : public CdsApi {
public:
MockCdsApi();
~MockCdsApi() override;

MOCK_METHOD(void, initialize, ());
MOCK_METHOD(void, setInitializedCb, (std::function<void()> callback));
MOCK_METHOD(const std::string, versionInfo, (), (const));

std::function<void()> initialized_callback_;
};
} // namespace Upstream
} // namespace Envoy
23 changes: 23 additions & 0 deletions test/mocks/upstream/cluster.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "cluster.h"

#include "gmock/gmock.h"
#include "gtest/gtest.h"

namespace Envoy {
namespace Upstream {
using ::testing::_;
using ::testing::Invoke;
using ::testing::Return;
MockCluster::MockCluster() {
ON_CALL(*this, info()).WillByDefault(Return(info_));
ON_CALL(*this, initialize(_))
.WillByDefault(Invoke([this](std::function<void()> callback) -> void {
EXPECT_EQ(nullptr, initialize_callback_);
initialize_callback_ = callback;
}));
}

MockCluster::~MockCluster() = default;

} // namespace Upstream
} // namespace Envoy
33 changes: 33 additions & 0 deletions test/mocks/upstream/cluster.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once

#include <functional>

#include "envoy/upstream/upstream.h"

#include "test/mocks/upstream/cluster_info.h"

#include "gmock/gmock.h"
#include "gtest/gtest.h"

namespace Envoy {
namespace Upstream {
class MockCluster : public Cluster {
public:
MockCluster();
~MockCluster() override;

// Upstream::Cluster
MOCK_METHOD(HealthChecker*, healthChecker, ());
MOCK_METHOD(ClusterInfoConstSharedPtr, info, (), (const));
MOCK_METHOD(Outlier::Detector*, outlierDetector, ());
MOCK_METHOD(const Outlier::Detector*, outlierDetector, (), (const));
MOCK_METHOD(void, initialize, (std::function<void()> callback));
MOCK_METHOD(InitializePhase, initializePhase, (), (const));
MOCK_METHOD(const Network::Address::InstanceConstSharedPtr&, sourceAddress, (), (const));

std::shared_ptr<MockClusterInfo> info_{new ::testing::NiceMock<MockClusterInfo>()};
std::function<void()> initialize_callback_;
Network::Address::InstanceConstSharedPtr source_address_;
};
} // namespace Upstream
} // namespace Envoy
Loading