Skip to content

Commit

Permalink
filters: Add test/server:filter_config_test (envoyproxy#14746)
Browse files Browse the repository at this point in the history
As part of envoyproxy#14470, I'll be modifying the base filter interface to include an overridable dependencies() function. This is prep work.

Risk Level: Low (test only)
Doc Change: n/a
Release Notes: n/a
Signed-off-by: Auni Ahsan <[email protected]>
  • Loading branch information
auni53 committed Jan 25, 2021
1 parent 201edce commit 7ccae76
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/server/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ envoy_cc_test(
],
)

envoy_cc_test(
name = "filter_config_test",
srcs = ["filter_config_test.cc"],
deps = [
"//include/envoy/server:filter_config_interface",
"//source/extensions/filters/http/common:pass_through_filter_lib",
"//test/mocks/server:server_mocks",
],
)

envoy_cc_test(
name = "hot_restart_impl_test",
srcs = envoy_select_hot_restart(["hot_restart_impl_test.cc"]),
Expand Down
42 changes: 42 additions & 0 deletions test/server/filter_config_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "envoy/server/filter_config.h"

#include "extensions/filters/http/common/pass_through_filter.h"

#include "test/mocks/server/factory_context.h"

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

namespace Envoy {
namespace {

class TestHttpFilterConfigFactory : public Server::Configuration::NamedHttpFilterConfigFactory {
public:
TestHttpFilterConfigFactory() = default;

Http::FilterFactoryCb
createFilterFactoryFromProto(const Protobuf::Message&, const std::string&,
Server::Configuration::FactoryContext&) override {
return [](Http::FilterChainFactoryCallbacks& callbacks) -> void {
callbacks.addStreamDecoderFilter(std::make_shared<Http::PassThroughDecoderFilter>());
};
}

ProtobufTypes::MessagePtr createEmptyConfigProto() override { return nullptr; }
ProtobufTypes::MessagePtr createEmptyProtocolOptionsProto() override { return nullptr; }

std::string name() const override { return "envoy.test.http_filter"; }
std::string configType() override { return ""; };
};

TEST(NamedHttpFilterConfigFactoryTest, CreateFilterFactory) {
TestHttpFilterConfigFactory factory;
const std::string stats_prefix = "foo";
Server::Configuration::MockFactoryContext context;
ProtobufTypes::MessagePtr message{new Envoy::ProtobufWkt::Struct()};

factory.createFilterFactoryFromProto(*message, stats_prefix, context);
}

} // namespace
} // namespace Envoy

0 comments on commit 7ccae76

Please sign in to comment.